我刚刚写了这个非常简单的手写数字识别。 Here is 8kb archive使用以下代码 + 十个 .PNG 图像文件。它有效:被广泛认为是 .
简而言之,数据库的每个数字(50x50 像素 = 250 个系数)被汇总为一个 10 系数向量(通过保留 10 个最大奇异值,请参阅 Low-rank approximation with SVD )。
然后,为了识别该数字,我们最小化与数据库中的数字的距离。
from scipy import misc
import numpy as np
import matplotlib.pyplot as plt
digits = []
for i in range(11):
M = misc.imread(str(i) + '.png', flatten=True)
U, s, V = np.linalg.svd(M, full_matrices=False)
s[10:] = 0 # keep the 10 biggest singular values only, discard others
S = np.diag(s)
M_reduced = np.dot(U, np.dot(S, V)) # reconstitution of image with 10 biggest singular values
digits.append({'original': M, 'singular': s[:10], 'reduced': M_reduced})
# each 50x50 pixels digit is summarized into a vector of 10 coefficients : the 10 biggest singular values s[:10]
# 0.png to 9.png = all the digits (for machine training)
# 10.png = the digit to be recognized
toberecognizeddigit = digits[10]
digits = digits[:10]
# we find the nearest-neighbour by minimizing the distance between singular values of toberecoginzeddigit and all the digits in database
recognizeddigit = min(digits[:10], key=lambda d: sum((d['singular']-toberecognizeddigit['singular'])**2))
plt.imshow(toberecognizeddigit['reduced'], interpolation='nearest', cmap=plt.cm.Greys_r)
plt.show()
plt.imshow(recognizeddigit['reduced'], interpolation='nearest', cmap=plt.cm.Greys_r)
plt.show()
问题:
代码可以运行(您可以运行 ZIP 存档中的代码),但是我们如何改进它以获得更好的结果?(我认为主要是数学技巧)。
例如,在我的测试中,9 和 3 有时会相互混淆。
最佳答案
数字识别可能是一个相当困难的领域。特别是当数字以非常不同或不清楚的方式书写时。为了解决这个问题,人们采取了很多方法,整个比赛都致力于这个主题。有关示例,请参阅Kaggle's digit recognizer competition 。本次比赛基于众所周知的MNIST data set 。在那里的论坛中,您会发现很多解决此问题的想法和方法,但我会给出一些快速建议。
很多人将这个问题视为分类问题。解决此类问题的可能算法包括 kNN、神经网络或梯度提升等。
但是,通常仅靠算法不足以获得最佳分类率。提高分数的另一个重要方面是特征提取。这个想法是计算能够区分不同数字的特征。该数据集的一些示例特征可能包括彩色像素的数量,或者可能是数字的宽度和高度。
尽管其他算法可能不是您正在寻找的算法,但添加更多功能也可能可以提高您当前使用的算法的性能。
关于python - 简单(有效)手写数字识别: how to improve it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34116526/