← All AI/ML articles

Ensemble learning, visualised.

One model makes one set of mistakes. A crowd of models, each a little different, makes mistakes that partly cancel out. Build a crowd live and see why it usually wins.

1. Bag the crowd2. Boost the mistakes3. Compare them
class Aclass Btest points (never used to train)
Click to add a training point of the chosen class. Double-click a point to remove it. Stronger background colour means a more confident vote.
Train accuracy0
Test accuracy0
Models voting0
Verdict-
Behind the scenes · 1

Each model alone, then the crowd

These are the first seven models of the current ensemble, each drawn on its own, followed by the combined vote. In bagging, every tree sees a random bootstrap sample (hollow dots were left out). In boosting, each tree is trained on re-weighted data: big dots are the points earlier trees got wrong. Notice how weak the individuals look next to the ensemble.



Behind the scenes · 2

More models, better votes

Test accuracy as you add models, for each method on the same data and tree depth. The single tree is a flat line, since it never changes. Bagging climbs and levels off as variance is averaged away. Boosting keeps correcting mistakes and can climb higher, but on very noisy data it may start chasing noise. Click the chart to set the number of models.


single treebaggingboostingdotted line = train accuracy of the selected method

Behind the scenes · 3

Variance versus bias

Bagging attacks variance: deep trees overfit in different ways, and averaging them cancels the wobble. Boosting attacks bias: shallow stumps are too simple alone, and stacking them step by step builds a flexible boundary. This table runs all three methods with your current depth and number of models. Click a row to use it.



Other ensembles follow the same idea: random forests add random features to bagging, and stacking trains a final model to blend different models' outputs. What matters is that the members are accurate and different from one another.

Experiment

Break it on purpose

Overfit a lone tree

Noisy moons and a deep single tree. It threads every training point, so train accuracy is high but test accuracy drops.

Bag the crowd

Keep the same data and deep trees, but vote with 40 bootstrap trees. The wobbly boundary smooths out and test accuracy rises.

Boost weak stumps

Use depth-1 stumps, which are too simple alone. Forty boosted stumps build a much better curved boundary.

Check yourself

Three quick questions

Key takeaways

  • An ensemble combines many models so that their individual errors partly cancel.
  • Bagging trains models in parallel on bootstrap samples and takes a vote. It reduces variance.
  • Boosting trains models in sequence, each focusing on the previous mistakes, and takes a weighted vote. It reduces bias.
  • Diversity matters: identical models add nothing, so ensembles need members that make different errors.
  • Trade-offs: ensembles cost more to train and are harder to interpret, and boosting can overfit very noisy data.
← Back to all articles