mb

k-nearest neighbours

k-nearest neighbours does not learn a line at all. it keeps every point, and to label a new spot it finds the k closest ones and lets them vote. the shading is that vote, asked at every spot on the plot.

24 points

shaded: circles win the vote. inked: the boundary. thin lines: the picked spot's k nearest. dashed: how far they reach

arrow keys move the crosshair, shift for finer steps. tap to place. keys: arrows, enter, backspace to erase

3
vote
0● 3□
says
square
held out
17/24

this circle, left out of its own vote, gets 0 circles and 3 squares: square

  1. □ 0.30
  2. □ 0.35
  3. □ 0.36

held out: each point voted on by its k nearest without itself. a tie goes to the nearest point.

try this

  1. set k to 1. every stray point gets an island of its own, because the nearest point to it is itself.
  2. slide k up to 15. the islands are gone and the boundary smooths into one sweep, since each vote now takes in most of the points.
  3. under more, switch to manhattan and set k back to 1. distance now runs along the grid, so the islands turn blocky.