knn 进行手写数字识别
生活随笔
收集整理的這篇文章主要介紹了
knn 进行手写数字识别
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
數(shù)據(jù)集使用了Keras的datasets
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import classification_report
from keras.datasets import mnist(x_train_tmp, y_train_tmp), (x_test_tmp, y_test_tmp) = mnist.load_data()
x_test_new = x_test_tmp.reshape(x_test_tmp.shape[0], -1)
total_num = x_test_new.shape[0]
test_num = int(total_num / 10)
x_test = x_test_new[:test_num]
y_test = y_test_tmp[:test_num]
x_train = x_test_new[test_num:]
y_train = y_test_tmp[test_num:]classifier = KNeighborsClassifier(n_neighbors=5)
classifier.fit(x_train, y_train)y_pred = classifier.predict(x_test)
print(classification_report(y_test, y_pred))
打印結(jié)果如下:
precision recall f1-score support0 0.94 0.99 0.97 851 0.91 1.00 0.95 1262 0.97 0.91 0.94 1163 0.93 0.93 0.93 1074 0.91 0.91 0.91 1105 0.95 0.92 0.94 876 0.97 0.97 0.97 877 0.89 0.91 0.90 998 0.95 0.83 0.89 899 0.86 0.87 0.87 94accuracy 0.93 1000macro avg 0.93 0.92 0.93 1000
weighted avg 0.93 0.93 0.93 1000
?
總結(jié)
以上是生活随笔為你收集整理的knn 进行手写数字识别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OpenCV Python 2 数字识别
- 下一篇: SVM进行手写数字识别