赞
踩
分别用逻辑回归、线性回归、K近邻、决策树、贝叶斯和SVM6个算法对iris数据集进行分类,并采用交叉验证计算模型的准确率。
加载一些库:
- from sklearn.datasets import load_iris
- from sklearn.model_selection import train_test_split
- from sklearn.model_selection import KFold
- from sklearn.model_selection import cross_val_score
- from sklearn.metrics import classification_report
- from sklearn.metrics import confusion_matrix
- from sklearn.metrics import accuracy_score
- from sklearn.linear_model import LogisticRegression
- from sklearn.tree import DecisionTreeClassifier
- from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
- from sklearn.neighbors import KNeighborsClassifier
- from sklearn.naive_bayes import GaussianNB
- from sklearn.svm import SVC
- from matplotlib import pyplot
加载数据集:
- #加载数据集
- data = load_iris()
- X = data['data']
- y = data['target']
训练集和测试集的
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。