gpt4 book ai didi

python - 简单(工作)手写数字识别 : how to improve it?

转载 作者:行者123 更新时间:2023-11-28 22:40:04 25 4
gpt4 key购买 nike

我刚刚写了这个非常简单的手写数字识别。 Here is 8kb archive使用以下代码 + 十个 .PNG 图像文件。它有效:enter image description here被公认为enter image description here .

简而言之,数据库的每个数字(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com