MNIST 数据集是经典的手写数字识别数据集,每个样本28*28
精简版MNIST:一共1797个样本,每个样本8*8,sklearn自带
完整版MNIST:一共6万个样本(5万个训练,1万个测试),每个样本28*28
http://deeplearning.net/data/mnist/mnist.pkl.gz
# 引入包
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn import preprocessing
from sklearn.metrics import accuracy_score
from sklearn.datasets import load_digits
# 加载数据
digits = load_digits()
data = digits.data
# 数据预处理
# 采用Z-Score规范化
ss = preprocessing.StandardScaler()
train_ss_x = ss.fit_transform(train_x)
test_ss_x = ss.transform(test_x)
# 创建LR分类器
lr = LogisticRegression()
lr.fit(train_ss_x, train_y)
predict_y=lr.predict(test_ss_x)
print('LR准确率: %0.4lf' % accuracy_score(test_y, predict_y))
LR准确率: 0.9644
网友评论