Skip to content

Instantly share code, notes, and snippets.

@lettergram
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lettergram/74f7f5415a3e5a5d5079 to your computer and use it in GitHub Desktop.
Save lettergram/74f7f5415a3e5a5d5079 to your computer and use it in GitHub Desktop.
PCA OCR Identification
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