Skip to content
dgDavid Gray
All work

Handwritten digit recognition with weighted KNN

A KNN classifier for handwritten digits, plus a k-value optimizer that collapses repeated distance calculations into a single pass.

Type
School
Year
2020
Built with
Python · KNN · Optimization

Classify a handwritten digit from a 28×28 grid of pixels, each an integer between 0 and 255. The KNN part is textbook. The part I actually cared about was the cost of choosing k.

The naive approach re-runs the whole distance calculation for every candidate value of k. I wrote an optimizer that reduces this to one instance of the distance computation per unclassified object, then evaluates every candidate k against those already-computed neighbours.

The full write-up, including the accuracy comparison across k values, is in the research report.

Let's talk

Have something hard that has to work?

Contract work, a full-time role, or a problem you want a second opinion on — I read every message and reply to the ones that aren't a template.

Email me

Usually replies within a day or two · St. Louis, Missouri