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()
显示代码内容
原文地址:https://www.cnblogs.com/hurt/p/10801838.html
时间: 2024-10-19 14:27:39