k-Nearest Neighbours

If similar examples tend to have similar answers, nearby labelled examples may help us predict a new one. We still need to decide how to measure distance and how many neighbours to ask.

13 sections · 10 questions · 4 coding challenges

1 / 13

Could a Previous Example Supply the Answer?

BOTIE

Imagine receiving an unfamiliar specimen with several measurements. You already have labelled specimens. Before trying to write a complete rule for each class, a reasonable first question is whether any of the known specimens look similar to this one.

Cover and Hart analysed nearest-neighbour classification in 1967. Their work helped establish that a very simple decision rule could have meaningful statistical properties: retain examples and classify a new observation using a nearby labelled observation. Those results depend on assumptions; they are not a promise that every choice of measurements or distance will work.

Using several neighbours extends the same idea. We find nearby examples and let their labels vote, or average their values for regression. A small neighbourhood follows local detail; a larger one smooths across more observations. The method's simplicity makes its dependency clear: the measurements and distance must place meaningfully similar cases near one another.

Sources for this history