商业数据分析--手写字体识别
声明
本文代码均保存在
https://github.com/super-213/business_data_analysis
有需要的可以自行下载
查看数据
1 | df = pd.read_excel('手写字体识别.xlsx' |
| 对应数字 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | … | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
数据划分
1 | X = df.drop(columns='对应数字') |
KNN
1 | from sklearn.neighbors import KNeighborsClassifier |
Accuracy: 0.9534883720930233
测试
1 | from PIL import Image |
图片中的数字为:4
SVM
1 | from sklearn.svm import SVC |
SVM模型的准确率为:0.9715762273901809
测试
1 | answer = rf.predict(arr_new) |
图片中的数字为:4
随机森林
1 | from sklearn.ensemble import RandomForestClassifier |
随机森林模型的准确率为:0.9689922480620154
测试
1 | answer = rf.predict(arr_new) |
图片中的数字为:4
MLP
1 | from sklearn.neural_network import MLPClassifier |
神经网络模型的准确率为:0.958656330749354
测试
1 | answer = rf.predict(arr_new) |
图片中的数字为:4
CNN
1 | df = pd.read_excel('手写字体识别.xlsx') |
Epoch 1/10
/opt/anaconda3/envs/tf-metal/lib/python3.11/site-packages/keras/src/layers/convolutional/base_conv.py:113: UserWarning: Do not pass an input_shape/input_dim argument to a layer. When using Sequential models, prefer using an Input(shape) object as the first layer in the model instead.
super().init(activity_regularizer=activity_regularizer, **kwargs)
2025-09-23 20:17:35.573018: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:117] Plugin optimizer for device_type GPU is enabled.
49/49 ━━━━━━━━━━━━━━━━━━━━ 4s 33ms/step - accuracy: 0.1034 - loss: 2.3043 - val_accuracy: 0.0749 - val_loss: 2.3025
Epoch 2/10
49/49 ━━━━━━━━━━━━━━━━━━━━ 1s 13ms/step - accuracy: 0.1028 - loss: 2.3010 - val_accuracy: 0.1137 - val_loss: 2.2969
Epoch 3/10
49/49 ━━━━━━━━━━━━━━━━━━━━ 1s 11ms/step - accuracy: 0.1713 - loss: 2.2660 - val_accuracy: 0.2481 - val_loss: 2.1901
Epoch 4/10
49/49 ━━━━━━━━━━━━━━━━━━━━ 1s 11ms/step - accuracy: 0.5184 - loss: 1.9033 - val_accuracy: 0.6382 - val_loss: 1.4705
Epoch 5/10
49/49 ━━━━━━━━━━━━━━━━━━━━ 1s 12ms/step - accuracy: 0.7673 - loss: 1.0627 - val_accuracy: 0.8062 - val_loss: 0.7945
Epoch 6/10
49/49 ━━━━━━━━━━━━━━━━━━━━ 1s 11ms/step - accuracy: 0.8649 - loss: 0.5883 - val_accuracy: 0.8527 - val_loss: 0.5462
Epoch 7/10
49/49 ━━━━━━━━━━━━━━━━━━━━ 1s 12ms/step - accuracy: 0.8908 - loss: 0.4113 - val_accuracy: 0.8786 - val_loss: 0.4564
Epoch 8/10
49/49 ━━━━━━━━━━━━━━━━━━━━ 1s 12ms/step - accuracy: 0.9089 - loss: 0.3249 - val_accuracy: 0.9044 - val_loss: 0.3793
Epoch 9/10
49/49 ━━━━━━━━━━━━━━━━━━━━ 1s 11ms/step - accuracy: 0.9211 - loss: 0.2893 - val_accuracy: 0.9018 - val_loss: 0.3861
Epoch 10/10
49/49 ━━━━━━━━━━━━━━━━━━━━ 1s 11ms/step - accuracy: 0.9302 - loss: 0.2541 - val_accuracy: 0.9173 - val_loss: 0.3233
测试
1 | from PIL import Image |
1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 582ms/step
图片中的数字为:4
- Title: 商业数据分析--手写字体识别
- Author: 姜智浩
- Created at : 2025-09-23 11:45:14
- Updated at : 2025-09-23 20:27:59
- Link: https://super-213.github.io/zhihaojiang.github.io/2025/09/23/20250923商业数据分析--手写字体识别/
- License: This work is licensed under CC BY-NC-SA 4.0.