SVM进行手写数字识别
生活随笔
收集整理的這篇文章主要介紹了
SVM进行手写数字识别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用了TensorFlow中的mnist數據集
from sklearn import svm
import numpy as np
from sklearn.metrics import classification_report
from tensorflow.keras.datasets.mnist import load_data(x_train, y_train), (x_test, y_test) = load_data()
x_train = x_train.reshape(x_train.shape[0], -1)
x_test = x_test.reshape(x_test.shape[0], -1)# 獲取一個支持向量機模型
predictor = svm.SVC(gamma='scale', C=1.0, decision_function_shape='ovr', kernel='rbf')
# 把數據丟進去
predictor.fit(x_train, y_train)y_pred = predictor.predict(x_test)
print(classification_report(y_test, y_pred))
準確率打印
precision recall f1-score support0 0.98 0.99 0.99 9801 0.99 0.99 0.99 11352 0.98 0.97 0.98 10323 0.97 0.99 0.98 10104 0.98 0.98 0.98 9825 0.99 0.98 0.98 8926 0.99 0.99 0.99 9587 0.98 0.97 0.97 10288 0.97 0.98 0.97 9749 0.97 0.96 0.97 1009accuracy 0.98 10000macro avg 0.98 0.98 0.98 10000
weighted avg 0.98 0.98 0.98 10000
?
總結
以上是生活随笔為你收集整理的SVM进行手写数字识别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: knn 进行手写数字识别
- 下一篇: 使用OpenCV进行SVM分类demo