← All AI/ML articles

Decision trees, visualised.

A decision tree is a flowchart of yes/no questions. Watch it carve the plane into boxes, see how it picks each question, and learn when to stop it growing.

1. Grow the tree2. Find the best split3. Prune it back
class Aclass Btest points (never used to grow the tree)
Click to add a training point of the chosen class. Double-click a point to remove it. White lines are the splits.
Train accuracy0
Test accuracy0
Leaves0
Verdict-
Behind the scenes · 1

How one split is chosen

At the root, the tree tries every threshold on both x and y. For each, it measures how mixed the two sides are using impurity (0 = one class only), weights them by size, and keeps the lowest. The drop from the parent's impurity is the gain.


Behind the scenes · 2

Too shallow, just right, too deep

Each depth is a different tree. Train accuracy only climbs as the tree grows. Test accuracy peaks, then slips: deep trees carve tiny boxes around single noisy points. Click the chart to try a depth.


Cyan = train, pink = test. The white line marks your current depth.

Behind the scenes · 3

Reading the tree, and pruning it

Every path from the root to a leaf is a rule. Requiring more points in each leaf stops the tree from isolating single outliers. This table regrows your current depth at each minimum leaf size. Click a row to use it.


Too large a minimum leaf size and the tree cannot make the splits it needs, so it underfits. Tune it with test accuracy.

Experiment

Break it on purpose

Underfit it

XOR corners with a depth-1 tree. One cut cannot separate four corners, so accuracy stays near a coin flip.

Overfit it

Noisy clusters with depth 10 and leaves of one point. The tree builds little islands around every mislabeled dot.

Prune it

Keep depth 10 but demand bigger leaves. The islands vanish and test accuracy recovers.

Check yourself

Three quick questions

Key takeaways

  • A decision tree asks one yes/no question per node, such as "is x ≤ 1.2?", until it reaches a leaf.
  • Splits are chosen to make the two sides as pure as possible (lowest Gini or entropy).
  • Every split is axis-aligned, so the regions are rectangles. That is why diagonal and circular patterns need many splits.
  • Depth controls flexibility: a tree grown until every leaf is pure will memorise the noise.
  • Pruning (max depth, min leaf size) and more data keep trees honest. Judge them on test accuracy.
← Back to all articles