UgraByte

Decision Boundary Explorer — See How Classifiers Split Data

Place two classes of labelled points and watch three algorithms disagree about where the line goes.

Loading the interactive version…

What this actually is

Supervised learning is the paradigm where the training data arrives with the answers attached. Every example is a pair — an input, and the correct label for it — and the algorithm's job is to find a rule that reproduces those labels well enough to trust on inputs it has never seen.

When a classifier works on two input features, that rule can be drawn. Every position on the plane is a possible input, and the model assigns each one to a class, so the plane divides into coloured regions. The line where they meet is the decision boundary. Given identical data, different algorithms draw strikingly different boundaries, and that difference is a statement about what each one assumed before it saw anything.

What you’re watching

The dots are your labelled training data. Pick a class, then click or tap empty canvas to add a point. The shaded background is the model's prediction for every other position on the plane, recomputed each time you add a point or change a control.

k-NN never builds a model. It keeps your points, and to classify a position it finds the k nearest and takes a vote. At k=1 the boundary wraps tightly around individual dots, including ones that look like mistakes — that jagged edge is overfitting made visible. Raise k and it smooths, because a single odd point gets outvoted.

Logistic regression can only draw a straight line, so given two classes no line can separate, it settles for the line that gets the most points right. The decision tree splits on one feature at a time, so its boundary is always built from horizontal and vertical cuts; a diagonal comes out as a staircase.

How to drive it

  1. Choose a class, then click or tap the canvas to place labelled points. Switch classes and add a second group somewhere else.

  2. Change the algorithm and watch the same points produce a different boundary.

  3. With k-NN selected, drag k from 1 upward and watch the boundary go from jagged to smooth.

  4. Try to build a dataset logistic regression cannot handle — two classes arranged in rings, or a diagonal split the tree has to approximate in steps.

How this relates to real systems

Production classifiers work in far more than two dimensions — a fraud model might read several hundred features — and there the boundary is a surface nobody can look at. That is why the flat version is worth studying: these are the shapes those models make, drawn somewhere you can see them.

The tradeoff is real too. A boundary that classifies every training point correctly is the failure mode every team is trying to avoid, which is why models are scored on held-out data instead. Logistic regression losing to a curved dataset is why teams reach for gradient boosting; its winning on a separable one is why, just as often, they do not.

Frequently asked questions

What is a decision boundary?
It is the dividing line between the regions a classifier assigns to different classes. On one side the model predicts class A, on the other class B, and along the boundary itself the prediction is a coin flip. It is a property of the trained model rather than of the data, which is why three algorithms can produce three different boundaries from the same points.
Why does k-NN with k=1 look so jagged?
Because with k=1 every single point gets its own territory, including points that are mislabelled or unusual. The model reproduces the training data perfectly and generalises badly, which is the textbook definition of overfitting. Increasing k averages over more neighbours, which trades that perfect training accuracy for a smoother boundary that usually does better on new data.
Why can't logistic regression draw a curve?
Because it fits a weighted sum of the input features and passes the result through a single squashing function, and the set of points where that sum crosses its midpoint is always a straight line in the original feature space. It can produce curves, but only if you feed it curved features — squares, products, distances — which is a manual step called feature engineering rather than something the algorithm discovers.
Why is the decision tree's boundary made of rectangles?
Each split in the tree is a test on one feature against one threshold, like "is x greater than 0.4", which cuts the plane with a line parallel to an axis. Stacking those cuts can only ever produce axis-aligned rectangles, so a diagonal boundary comes out as a staircase. Deeper trees make finer steps, which approximates the diagonal better and overfits faster.
Is this the same maths real libraries use?
It is the same algorithms, implemented plainly and at a small enough scale to run on every keystroke. k-NN here is an exact brute-force search rather than a spatial index, logistic regression uses straightforward gradient descent rather than a tuned solver, and the tree uses Gini impurity with a shallow depth cap. The behaviour you observe is genuine; the engineering that makes those algorithms fast on millions of rows is not the point here.