This is a very simple machine-learning demo that runs entirely in your browser.
1. You provide examples
Every time you draw a shape and click a label (Circle, Square or Triangle), the program extracts a few geometric features from your drawing:
- How round it is (circularity)
- Its aspect ratio (width ÷ height)
- A rough count of sharp corners
- Overall size
2. The algorithm: k-Nearest Neighbors (k-NN)
When you ask it to classify a new drawing, it:
- Extracts the same features from the new shape
- Measures the distance between these features and every example you previously gave it
- Looks at the 5 closest examples (the “neighbors”)
- Takes a majority vote among those 5 neighbors
That’s it. No neural network, no training loop with gradients — just pure comparison with the examples you supplied.
Why it sometimes fails
Freehand drawings vary a lot. The features are intentionally simple so the whole process stays transparent and educational. More (and more consistent) examples usually improve accuracy.
This is the classic supervised-learning pattern: labeled data → simple model → prediction. The same idea powers almost every modern AI system, just at a much larger scale.