Skip to content

sort points into groups

Each point has a class: triangle, square or circle. A test point is one whose class the racers are not shown. k-means sorts the test points into groups without seeing a class, and each group takes the class most of its points hold. k-nearest neighbours learns from training points whose class it knows. Four racers race: k-nearest neighbours, and k-means from three starts. Most test points right wins.

k-means never sees a class. It puts the 12 test points into groups, and each group takes the class most of its points hold. When classes tie for most, the group takes the tied class that comes first in the order triangle, square, circle: a group of 3 squares and 3 circles takes square. A test point is right when its group's class is its own.

k-means starts with one centre for each group: its k is the number of groups. It joins each point to its nearest centre, moves each centre to the middle of its points, and repeats until no centre moves. Each pass is a round. k-means starts three ways. From the corners: (0, 0) and (10, 10), and (0, 10) for a third group. From the first test points, one for each group. From the last test points. k-nearest neighbours learns from 9 training points with their classes. Its k is how many nearest training points vote, here 3: a test point gets the class most of them hold, or the nearest one's class when all three differ.

Most right wins. When racers tie, the one that measured the fewest distances wins; tied on that too, they all win. Each time a racer works out how far a point is from a centre or a training point, that is one distance. In each racer's picture below, the tint is the class a new point there would get. A cross marks where each k-means centre ended, and a circle is drawn round each test point its racer got wrong.

Start on two blobs in two groups.

the shape of the points

how many groups

k-means puts 12 test points into 2 groups without seeing a single class. k-nearest neighbours learns from 9 training points first.

Without scripts the keys cannot redraw, so the race shows two blobs in 2 groups.

which suits these points

On two blobs in 2 groups, k-nearest neighbours, k-means from the first test points and k-means from the last test points each got 12 of 12 test points right. Of those, k-means from the first test points measured the fewest distances: 48, against 108 for k-nearest neighbours and 72 for k-means from the last test points.

k-nearest neighbours12k-means from the corners6k-means from the first test points12k-means from the last test points12
Each row is one racer, each column one test point: a dot is filled if that racer got it right, hollow if wrong.

each racer's own page

k-nearest neighbours

k is 3
02468100246810

12 of 12 right, 108 distances measured

k-means

from the corners
02468100246810

6 of 12 right, 48 distances measured

k-means

from the first test points
02468100246810

12 of 12 right, 48 distances measured

k-means

from the last test points
02468100246810

12 of 12 right, 72 distances measured

  • a training point, which k-nearest neighbours learns from
  • where a k-means centre ended
  • a test point, drawn as its true class
  • a test point the racer gave the wrong class
  • the class the racer gives a new point there
  • a spot left plain, where the racer gives no class

On the start, k-nearest neighbours measures 9 distances for each of the 12 test points: 9 times 12 is 108. k-means measures 12 times 2, 24 distances, each round: one from each test point to each centre. From the first test points, its second round moves no centre, so it stops: 2 times 24 is 48.

every shape in 2 groups, over five draws

A draw is a fresh set of points in the same shape. Each cell: test points right in five draws of 12 test points each, out of 60, and under it the distances measured. The most right on each row is in bold; where several tie, the ones that measured the fewest distances.

The start decides. On two blobs, the corners (0, 0) and (10, 10) lie just as far from one blob as from the other. From them, k-means makes two groups of 3 triangles and 3 squares each, so both take triangle and it gets only 6 of 12 right. Started at test points, it gets all 12. Over five draws, k-nearest neighbours wins only on a slant, in two groups and in three. In two groups, k-means from the first test points wins every other shape.

02468100246810
The start's 12 test points, k-means started at the corners (0, 0) and (10, 10). Each group takes 3 points from the top left blob and 3 from the bottom right one. Here a point's mark shows its group, not its class.
02468100246810
The same points started at the first two test points, (2, 6) and (8, 5): each blob is a group of its own.
the shapek-nearest neighboursk-means from the cornersk-means from the first test pointsk-means from the last test points
two blobs0246810024681060540 measured43312 measured60288 measured60312 measured
a ring round a middle0246810024681039540 measured37312 measured39312 measured39384 measured
a slant0246810024681056540 measured47432 measured49360 measured48264 measured
a corner0246810024681046540 measured42384 measured55384 measured49312 measured
noisy blobs0246810024681031540 measured45528 measured45360 measured44336 measured