基于python的数字识别_基于sklearn数字识别(python开发)

from sklearn import datasets
import matplotlib.pyplot as plt
digist = datasets.load_digits()
# print(digist.keys())
# print(digist.data[1],digist.target[1])
plt.figure()
plt.gray()
plt.matshow(digist.images[1])
plt.savefig('fig.png',bbox_inches='tight')
# 数据集的分类
from sklearn.model_selection import train_test_split
#random_state指定随机数种子。
print(digist.data)
X_train,X_test,Y_train,Y_test = train_test_split(digist.data,digist.target,test_size=0.2,random_state=1)
# print(X_train,X_test)
# print(X_train.shape)
from sklearn.neighbors import KNeighborsClassifier
knn_classifier = KNeighborsClassifier(n_neighbors=3)
knn_classifier.fit(X_train,Y_train)
# print(knn_classifier.predict(X_test))
# print(knn_classifier.predict(Y_test))
print(knn_classifier.score(X_test,Y_test))
本文地址:https://blog.csdn.net/yiweij/article/details/107092720
希望与广大网友互动??
【基于python的数字识别_基于sklearn数字识别(python开发)】点此进行留言吧!

    推荐阅读