Skip to content

put a point in a class

Each point has a class: triangle or square. Learn from training points, whose class you know, then give a class to new points, the test points. Four methods, the racers, race; the one that gets the most test points right wins.

Each test point has a true class the racer is not shown. The racer is right when the class it gives matches it.

k-nearest neighbours finds the k nearest training points (here k is 3) and gives the class most of them hold. The perceptron draws one straight line, triangles on one side and squares on the other. Each training point on the wrong side, or on the line, nudges the line; the step size, here 0.5, sets how big each nudge is. A point on the line gets no class. The decision tree asks at most 2 questions, such as: is the point past 4.5 across? Each answer cuts the picture in two; it gives the class most training points in the point's part hold. Naive Bayes cuts each axis into three bands and counts each class in each band. It scores each class: its share of all points, times its share in the point's band across, times its share in its band up. The higher score wins. Smoothing 1 adds 1 to every count, so no share is 0 and an empty band never makes a score 0.

Most right wins. When racers tie, the one that looked at training points the fewest times wins; each look is one point read. In each racer's picture below, the tint is the class it gives a point there, and a circle is drawn round each test point it got wrong.

Start on a ring: 9 training points, triangles in the middle and squares round them.

the shape of the points

how many training points

Each racer learns from 9 training points, then gives a class, triangle or square, to 12 test points it never saw.

Without scripts the keys cannot redraw, so the race shows a ring round a middle with 9 training points.

which suits these points

On a ring round a middle with 9 training points, naive Bayes put the most test points in the right class: 11 of 12, against 7 for k-nearest neighbours, 8 for perceptron and 8 for decision tree.

k-nearest neighbours7perceptron8decision tree8naive Bayes11
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

7 of 12 right, 108 training points read

perceptron

step size 0.5
02468100246810

8 of 12 right, 54 training points read

decision tree

2 questions deep
02468100246810

8 of 12 right, 139 training points read

naive Bayes

smoothing 1
02468100246810

11 of 12 right, 9 training points read

  • a training point, which the racer learns from
  • a test point, drawn as its true class
  • a test point the racer gave the wrong class, or none
  • 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 reads all 9 training points for each test point: 9 times 12 is 108. Naive Bayes counts each once: 9. The perceptron stops after a pass through all 9 with no mistake, or at 6 passes. On the ring every pass has a mistake, so 6 passes of 9 make 54. The decision tree weighs every question halfway between neighbouring values, 5 across and 5 up, on all 9 points: 10 times 9 is 90. The best splits off 2 squares; 7 questions on the 7 points left make 49, and 90 and 49 make 139.

every shape with 9 training points, over five draws

A draw is a fresh set of points in the same shape. Each cell: test points right over five draws, out of 60, and under it the training points read in those draws. The most right on each line is in bold; where two tie, the one that read fewer.

Five draws of 12 test points make 60. On a ring, squares lie on both sides of the triangles, so any line the perceptron draws leaves some on the wrong side. Over five draws it gets the fewest right: 35 of 60, with 9 training points. Naive Bayes gets the most: 49. On two blobs with 9 or 12 training points, k-nearest neighbours and the perceptron both get all 60 right, and the perceptron reads fewer. Over five draws, only a ring has one winner at all three sizes: naive Bayes, in bold in the table at 6, 9 and 12 training points. On each of the other shapes the winner changes: press 6, 9 or 12 to see it. Noisy blobs are two blobs with some points given the other class. That means 3 of the 12 test points, and 2 of 6, 3 of 9 or 3 of 12 training points.

the shapek-nearest neighboursperceptrondecision treenaive Bayes
two blobs0246810024681060540 read60108 read56529 read5245 read
a ring round a middle0246810024681039540 read35270 read45681 read4945 read
a slant0246810024681056540 read51153 read49600 read5345 read
a corner0246810024681046540 read43144 read48546 read4645 read
noisy blobs0246810024681031540 read26270 read31624 read2945 read