Chapter 2 · Machine learning basics
k-nearest neighbours
Classify a new point by looking at the k closest known examples.
Chapter 2 · Machine learning basics
Classify a new point by looking at the k closest known examples.
k = 1: 0 cyan and 1 magenta, so the new point is called magenta.
The new point is the big dot. The circle grows until it holds its k nearest known points, which then vote.
k-nearest neighbours does not build a formula. It simply stores every labelled example, like a map of points.
Drag the big dot (or use arrow keys) and move the k slider. The big dot takes the colour of the winning vote. The dark-edged points are its neighbours.
Verdict: Cyan. Only the single closest point decides, strays included.
Check-yourself score: if each stored point is hidden in turn and called by its 1 nearest others, 93% are called right. A simplified teaching version with thirty made-up points and straight-line distance.
In k-nearest neighbours, what does k stand for?
With k = 1, what decides the answer?
Which k better ignores a lone stray point?