基于sklearn数字识别(python开发)
程序员文章站
2023-11-06 23:46:10
from sklearn import datasetsimport matplotlib.pyplot as pltdigist = 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 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
上一篇: 目录
下一篇: Java深入学习(2):并发队列