Last active
August 29, 2015 14:17
-
-
Save lettergram/74f7f5415a3e5a5d5079 to your computer and use it in GitHub Desktop.
PCA OCR Identification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
u, sigma, test = train(read(), 30) | |
right = 0.0 | |
total = 0.0 | |
for img in test: | |
matrix = np.subtract(img[1], np.mean(img[1])) # Center | |
matrix = np.reshape(matrix, (-1, 1)) | |
covImg = np.dot(matrix, np.reshape(matrix, (1, -1))).T | |
index = 0; | |
best = 0.0 | |
for i in range(10): | |
if best < np.mean(covImg * sigma[i]): | |
index = i | |
best = np.mean(covImg * sigma[i]) | |
if img[0] == index: | |
right += 1.0 | |
total += 1.0 | |
print (right/total), total, img[0], index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment