使用pandassklearn等外部库进行iris数据的分类和绘图,并计算正确率
Posted hurt
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用pandassklearn等外部库进行iris数据的分类和绘图,并计算正确率相关的知识,希望对你有一定的参考价值。
from sklearn.model_selection import train_test_split from sklearn.datasets import load_iris from sklearn.neighbors import KNeighborsClassifier import pandas as pd import numpy as np from pandas.plotting import scatter_matrix import matplotlib.pyplot as plt data = load_iris() X_train, X_test, Y_train, Y_test = train_test_split( data.data, data.target, random_state=0) cheng = pd.DataFrame(data.data, columns=data.feature_names) scatter_matrix( cheng, figsize=( 10, 10), c=data.target, alpha=0.8, s=20, hist_kwds={ ‘bins‘: 30}) knn = KNeighborsClassifier(n_neighbors=5) knn.fit(X_train, Y_train) prelist = knn.predict(X_test) true_values = np.mean(prelist == Y_test) print(true_values) plt.show()
以上是关于使用pandassklearn等外部库进行iris数据的分类和绘图,并计算正确率的主要内容,如果未能解决你的问题,请参考以下文章