The idea
Ask one person to guess the number of sweets in a jar and they may be way off. Ask a hundred people and average the guesses, and you are usually close. That only works if people make different mistakes.
A forest forces its trees to disagree in two ways. Each tree may see a random resample of the data, and at each split it is only allowed to consider one randomly chosen feature ( or ). Diverse trees, averaged, give a steadier answer than any one of them.
How it learns
- For each tree, draw a bootstrap sample: points picked with replacement.
- Grow a decision tree on that sample using Gini impurity.
- At every split, pick or at random and find the best cut on that feature only.
- Repeat for the chosen number of trees.
- To predict, average the class probabilities from all trees.
Reading the picture
The background blends the votes of every tree. Strong colour means the trees agree; pale bands show where they split their votes. The boundary is still built from axis-aligned pieces, but it is far smoother than a single tree's.
With Bootstrap samples on, about a third of the points are left out of each tree. Out-of-bag accuracy scores each point using only the trees that never saw it, which gives a fair test score for free.
Try this
- On Moons, set Number of trees to 1. You see one jagged tree. Slide it up to 60 and watch the boundary smooth out.
- Compare Training accuracy with Out-of-bag accuracy. Training is near perfect; out-of-bag tells you what to actually expect.
- Turn off Bootstrap samples. Trees now differ only in their random feature choices, so they agree more and the shading becomes harder-edged.
- Try Spiral with Max depth 12. Forests can follow complex shapes that would make a single tree overfit badly.
The maths
Bootstrap
Left out
Prediction
Out-of-bag
Strengths and weaknesses
Good at
- Accurate out of the box with little tuning.
- Hard to overfit by adding more trees.
- Out-of-bag accuracy gives built-in validation.
Struggles with
- Loses the readability of a single tree.
- Many trees cost memory and prediction time.
- Boundaries remain axis-aligned underneath.