# %% md ## Iris数据集上用2维特征、2类分类可视化 #决策边界 #ROC曲线 #PR曲线 # %% import pandas as pd import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt # 特征缩放:数据标准化 from sklearn.preprocessing import StandardScaler from sklearn.metrics import roc_curve, auc # 将数据分割训练数据与测试数据 from sklearn.model_selection import train_test_split from sklearn.model_selection import GridSearchCV from sklearn.linear_model import LogisticRegression import seaborn as sns # 显示中文 plt.rcParams['font.sans-serif'] = ['Arial Unicode MS'] # %% # 读取数据 # csv文件没有列名,增加列名 # 花萼长度、宽度;花瓣长度、宽度 feat_names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'Class'] dpath = "./data/" df = pd.read_csv(dpath + "iris.csv", names=feat_names, header=None) # 通过观察前5行,了解数据每列(特征)的概况 df.head() # %% # 类别 unique_Class = df['Class'].unique() # %% # 只考虑两类分类:setosa vs. non_setosa target_map = {'Iris-setosa': 0, # 山鸢尾 'Iris-versicolor': 1, # 变色鸢尾 'Iris-virginica': 1} # 2,弗吉尼亚鸢尾 # Use the pandas apply method to numerically encode our attrition target variable df['Class'] = df['Class'].apply(lambda x: target_map[x]) df.head() # %% # 查看不同类别下特征的直方图,初步了解特征的可分性 # 3个类别的颜色 colors = ['blue', 'red', 'green'] # plot histogramdf.shape[0]
鸢尾花的逻辑回归实验
最新推荐文章于 2024-01-04 15:12:39 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)