Classifier
Train accuracy
Test accuracy
Iteration
Data
Add points of class
Model
Playback
View

More information about decision boundaries and classifiers

Six ways to draw a line between classes

Give a computer points of two or three colours and ask it to colour the rest of the plane: that is classification, and every method answers differently. Logistic regression draws a straight line or a smooth curve, k-nearest neighbours asks the neighbours, a decision tree cuts in steps, naive Bayes fits bell curves, a support vector machine looks for the widest margin and a neural network bends the boundary at will. Watch them train side by side on moons, circles, spirals and XOR, add your own points and see which one generalises to the test points. A classifier learns from labelled points and then gives every place in the plane a class: the coloured regions show what it would predict there, paler where it is less sure, and the dark line is the decision boundary, where two classes are equally likely. Six kinds of classifier learn in very different ways. Logistic regression draws a straight line, or a curve with polynomial features; k-nearest neighbours lets the k closest training points vote (move the mouse over the k-NN picture, or drag the diamond, to see a point's neighbours); a decision tree cuts the plane with straight cuts parallel to the axes; naive Bayes fits one bell curve per class and feature (the ellipses); a support vector machine finds the widest margin between the classes (the support vectors are ringed, the margins dashed), curved with the RBF kernel; a neural network bends the boundary freely. Press Play to watch them learn: epochs for logistic regression and the network, the SMO solver's steps for the SVM, split by split for the tree, more and more of the data for naive Bayes, k from 1 up for k-NN. Filled points train the classifier and hollow points test it: one that is much better on the training points than on the test points has overfitted. Compare all trains the six side by side. Click to add points of the chosen class, right-click for the next class, drag them, double-click one to delete it. Save image, record a video with a tick per step, or open the picture in the photo editor with the pencil, where the regions, the boundary, the details and each class's points are layers of their own.

How it works

  1. Press Play: all six classifiers learn the moons side by side, the coloured regions showing what each would predict and the dark line its decision boundary. The tiles name the best and the worst on the test points.
  2. Turn off Compare all and pick one classifier to watch it closely: logistic regression and the neural network epoch by epoch, the SVM's support vectors and margins as it solves, the tree split by split, naive Bayes' ellipses, k-NN as k grows.
  3. Change the dataset, the noise and the test share, and each classifier's settings: the polynomial degree, k, the tree's depth, the SVM's kernel, C and γ, the network's hidden units and epochs.
  4. Click to add points of the chosen class, right-click to add the next class, drag points and watch every boundary follow; over k-NN the mouse is a probe that shows its neighbours.

What a decision boundary is

A classifier is a rule that gives every input a class. With two numbers per point, every input is a place in the plane, so the rule colours the whole plane: its decision regions. Where two regions meet is the decision boundary, the places where the classifier finds two classes equally likely. The shading shows how sure it is: deep colour far from the boundary, pale near it. The boundary says more about a classifier than its accuracy alone: whether it can only draw straight lines, whether it follows every stray point, and what it would say about places where it has seen no data at all.

Six kinds of classifier

Logistic regression turns a weighted sum of the inputs into a probability, so its boundary is a straight line; adding x², xy, y² and higher powers as extra inputs bends it into a curve. k-nearest neighbours keeps every training point and lets the k nearest vote, so its boundary follows the data closely when k is small and smooths out as k grows. A decision tree asks one question after another, such as x below 0.7?, so its regions are rectangles. Gaussian naive Bayes models each class as a bell curve along each axis and picks the most probable class, giving curved, conic-shaped boundaries. A support vector machine puts the boundary as far as possible from both classes, and with the RBF kernel it can curve it round any shape. A neural network learns its own features in hidden layers and can bend the boundary into almost any form.

Training and test points

A classifier is only useful if it is right about points it has not seen. So some points, drawn hollow, are kept out of training and used only to test it. A classifier that is nearly perfect on its training points and much worse on the test points has overfitted: it has learned the noise, as a deep tree or k-NN with k = 1 does on overlapping clouds. One that is poor on both has underfitted, like a straight line on XOR. Between the two lies the right flexibility for the data, the bias–variance trade-off that every method's settings control.

No best classifier

Compare all shows the same data through six eyes, as in scikit-learn's famous classifier comparison. On round blobs almost any method works and simple ones are best. On moons and circles the straight-line methods fail unless they get extra features, while k-NN, the RBF SVM and the network succeed. On XOR a single line is hopeless but a tree or a network finds the four quadrants. No method wins on every problem, a fact made precise by the no free lunch theorems; choosing a model means matching its assumptions to the data.

Frequently asked questions

What is a decision boundary?

The line or curve that separates the places where a classifier predicts one class from those where it predicts another. Points exactly on it are equally likely to belong to either class. For two inputs it can be drawn in the plane, which is what the app does: the coloured regions are the classifier's predictions everywhere, and the dark line is where they change.

Which classifier is the best?

None in general. Logistic regression and naive Bayes are fast, simple and hard to overfit, but their boundaries are limited in shape. k-NN and the RBF support vector machine fit almost any shape, given enough data and the right k or γ. Trees are easy to read but blocky and prone to overfitting when deep. Neural networks are the most flexible and need the most care. Comparing them on the same data, as Compare all does, is the honest way to choose.

What are support vectors?

The training points that decide where a support vector machine puts its boundary: those on the margin, the band of width two around the boundary where the decision value lies between −1 and 1, and those inside it or on the wrong side. Every other point could be moved or removed without changing the boundary. The app rings them; dashed rings mark points inside the margin, whose weight has hit the limit C.

What do C and γ do in an SVM?

C is the penalty for points inside the margin or on the wrong side: a small C allows many and gives a wide, smooth margin, a large C tries hard to classify every training point and can overfit. γ sets how far the influence of one point reaches with the RBF kernel exp(−γ|x − x′|²): a small γ gives smooth, nearly straight boundaries, a large γ wraps tight islands round single points.

Why does a straight line fail on XOR?

In XOR the two classes sit in opposite corners, top left and bottom right against top right and bottom left, so no single straight line can put both of one class on one side. Minsky and Papert used this in 1969 to show the limits of one-layer perceptrons. A curved boundary is needed: polynomial features with the product xy, a decision tree's two cuts, an RBF kernel or a neural network with a hidden layer all solve it.

Can I use the picture?

Yes. Save gives a PNG at the size you choose, Save JSON writes the points, the split into training and test points and every classifier's accuracies, support vectors, splits or loss, Record films the training with a soft tick per step, and the pencil opens the picture in the PictorX photo editor with the background, the decision regions, the boundary, the support vectors, neighbours, splits or Gaussians, each class's points and the labels on layers of their own. In the editor itself it is under Apps ▸ Science ▸ Computing ▸ Decision Boundaries. Everything runs in your browser.

Decision Boundaries: how do I record a video?

Press the red Record button in the playback bar: it films what the stage shows. Press it again to stop, and the video is saved to your device. Recording is free; you only need to sign in. Without a subscription the video carries a small PictorX logo in a corner. The button beside Record opens the video options: the shape (as shown, square, story 9:16 or wide 16:9), the length (until you stop, or 5, 10, 15 or 30 seconds for social media) and the file: MP4, WebM or an animated GIF. For the sound, choose the app's own sounds or one of three music tracks: calm, bright or beat.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Go to Editor