Lab · c02.s02.L1

Nearest-neighbour playground

A prediction is the label of the nearest stored example, or the commonest label among the k nearest, read off a ranked distance list.

Question: How can the closest example be the answer?

Nearest-neighbour playgroundA square field holds twenty examples: circles upper left, crosses upper right, diamonds along the bottom, and a star marks the query. A dashed ball grows from the star to enclose the nearest one, three, then five examples; enclosed shapes are ringed, lines tie them to the star, and a panel lists the distances and counts labels into a prediction. At centre the nearest circle gives way to two crosses when k grows, so proximity, not a fitted rule, decides.Nearest-neighbour playgroundcirclecrossdiamondqueryQueryPlane 0.0 to 10.0 in x and y; the star snaps to steps of 0.5.(5.0, 5.0), k = 1NEAREST BY DISTANCEcircle #10.224Only the first row is consulted.VOTE AMONG THE k NEARESTcircle1 of 11.000cross0 of 10.000diamond0 of 10.000PREDICTIONcircle1 of 1 nearest is circle
Synthetic Synthetic: the 20 stored examples are invented coordinates, laid out to reproduce the three-class situation of the section's figure (after Manning et al., Fig. 14.6, as cited there); no measured data is shown. The frames rank the stored examples by distance and count the k nearest labels for k = 1, 3 and 5, at the default query and two nearby positions; 30 of the 441 query positions change the answer between k = 1 and k = 3.
Lab controls
5

Right: +0.5, Left: -0.5; Page Up: +2.0, Page Down: -2.0; Home: 0.0; End: 10.0

5

Up: +0.5, Down: -0.5; Page Up: +2.0, Page Down: -2.0; Home: 0.0; End: 10.0

1

Left/Right: previous/next value; Home: 1; End: 5

Frame 1 of 1: k = 1: one example decidesThe nearest stored example is the circle at distance 0.224. With k = 1 the vote has one member, so the prediction is circle; the other examples are not consulted.

k = 1: one example decides. The nearest stored example is the circle at distance 0.224. With k = 1 the vote has one member, so the prediction is circle; the other examples are not consulted.

Keyboard: Space plays or pauses, Left and Right step, Home goes to the first frame, End goes to the last frame.

Text description of this lab

A square field holds twenty examples: circles upper left, crosses upper right, diamonds along the bottom, and a star marks the query. A dashed ball grows from the star to enclose the nearest one, three, then five examples; enclosed shapes are ringed, lines tie them to the star, and a panel lists the distances and counts labels into a prediction. At centre the nearest circle gives way to two crosses when k grows, so proximity, not a fitted rule, decides.

Return to the section that hosts this lab

Caption status: synthetic. Every lab declares one of published, re-simulated, schematic, synthetic or interpolated.