欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-01-04 12:31:52
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

上一篇:

下一篇: