← All AI/ML articles

Random forest, visualised.

One decision tree is jumpy and easily fooled. Plant many slightly different trees, let them vote, and the crowd is smarter than any single tree. Click, grow and watch it happen.

1. Draw some data2. Grow the forest3. Watch the vote
Click to add a point of the selected class · Shift-click (or right-click) a point to remove it · White ring = the forest gets this point wrong.
Train accuracy0
OOB accuracy0
Points0
Behind the scenes · 1

Every tree sees a different dataset

Each tree trains on a bootstrap sample: draw n points with replacement. Some points get picked twice (bigger dots), and about 37% are never picked (hollow dots, called out-of-bag). Slide through the trees and see how differently each one carves up the plane.

How this tree chose its first split

Gini impurity = 1 − Σ p². 0 means a pure group; 0.5 is a perfect 50/50 mix. The tree picks the split with the lowest weighted impurity.

Behind the scenes · 2

The vote

Pick any spot on the map. Every tree casts one vote, and the forest answers with the majority. The shade of the map is simply the share of trees that vote for each colour. Click or drag the white dot.

One square per tree

Individual trees often disagree near the boundary. Averaging many of them smooths out their individual mistakes.

Behind the scenes · 3

Free test score: out-of-bag accuracy

Each point was left out of roughly a third of the trees. Let only those trees vote on it, and you get an honest test score with no separate test set. The curve shows how it improves as trees are added, then flattens.

Out-of-bag accuracy after 1, 2, 3 … trees. More trees never hurt; they just stop helping.

Why it works: each tree overfits in its own random way. Their mistakes point in different directions, so voting cancels much of the noise while keeping the signal.

Experiment

Break it on purpose

One deep tree

One tree, depth 8. It memorises every point and draws jagged islands around the noise.

Plant 50 trees

Same deep trees, but 50 of them voting. The islands melt into a smooth boundary.

Mislabelled data

Flip 15% of the labels and compare train accuracy with out-of-bag accuracy.

Check yourself

Three quick questions

Key takeaways

  • A tree asks a chain of yes/no questions, choosing splits that make groups purer (lower Gini).
  • Bagging trains each tree on a bootstrap sample, so every tree is different.
  • Random features at each split make the trees even less alike.
  • Voting averages away individual errors: lower variance, same bias.
  • OOB accuracy gives a built-in test score from the points each tree never saw.
← Back to all articles