How it Works
Every vertex of the 3D grid corresponds to a point in a 2D feature space (x₁, x₂). The coloured spheres are labelled training examples of three classes. For any point in the grid, the classifier finds the k nearest training examples and lets them vote on a class; the winning class's vote share becomes that point's confidence, mapped to both the landscape's height and its colour. There is no training phase and nothing is "learned" ahead of time — every click that adds a point changes the raw dataset the classifier looks up at query time, which is why the whole landscape can reshape instantly.
Two extra knobs change how the vote is counted. The distance metric switches between Euclidean distance (straight-line) and Manhattan distance (grid-step, "taxicab") between a query point and each training example. The voting mode switches between uniform votes (every one of the k neighbours counts equally) and distance-weighted votes (closer neighbours count more, so a single very close point can outvote several farther ones).
The "Leave-one-out accuracy" stat is a cheap generalisation estimate: every training point is temporarily removed from its own neighbour pool and reclassified using only the rest of the dataset, then checked against its true label. It updates after every click, slider move, or toggle — a direct, visible readout of how the current k, metric and weighting choice actually performs on the data you've planted.
Frequently Asked Questions
What is k-nearest neighbours (k-NN)?
k-NN is a supervised classification algorithm with no training phase: to label a new point it simply finds the k closest labelled examples in feature space and lets them vote. The "model" is the training set itself.
Why does the landscape get taller near clusters of one colour?
Height encodes confidence — the winning class's share of the k nearest votes. Deep inside a single-class cluster nearly all k neighbours agree, so confidence and height are near maximum. Near a boundary the vote is split, so the landscape dips toward a valley.
What does the k slider actually change?
k is how many nearest neighbours get a vote. A small k (1-3) lets the boundary hug every single point tightly, including noise. A large k smooths the boundary by averaging over a wider neighbourhood, at the risk of blurring genuinely separate regions together.
What is Leave-One-Out accuracy?
For every training point, the classifier is asked to predict its label using every other point but not itself, then the prediction is checked against the true label. It's a cheap way to estimate how well the current k, metric and weighting would generalise to points not yet seen.
How is this different from a neural network classifier?
There are no weights, layers or gradient descent here. k-NN is an instance-based ("lazy") learner — it stores the raw examples and defers all computation to prediction time, recomputing distances to every stored point. That's exactly why adding one click-point changes the landscape instantly, with nothing to retrain.