Ch.41: Ensemble Learning, the Introduction
Inspired by: YouTube
This is the start of a big, practical block of the series: ensemble learning. The idea shows up in almost every real machine learning project and almost every Kaggle solution, because it is usually the cheapest way to squeeze out a few more points of accuracy after everything else is done. This post is only the introduction: what the word means, why it works, and the four shapes it comes in. Each shape gets its own post afterwards.
There is no companion notebook for this video; the visuals below are regenerated from scratch with scikit-learn to make the same points the video makes with stock illustrations.
1. What "Ensemble" Means
Google "ensemble" and you get "a group of things viewed as a whole." In machine learning it means exactly that: instead of training one model, you train a collection of models and combine their outputs into one bigger model. That combined thing is the ensemble.
The base models can be anything: a linear regression, a decision tree, an SVM, a KNN, or ten thousand copies of the same algorithm. What matters is what you do with their answers, and (as Section 3 explains) how different they are from each other.
2. Wisdom of the Crowd
Before the mechanics, the belief the whole field rests on: a large, diverse crowd is often collectively smarter than any single expert in it. This is not an ML idea, it is everywhere:
- Audience polls. On Kaun Banega Crorepati, "ask the audience" is almost always right, far more reliably than any one person in the seats.
- Product reviews. A 4.5 rating from 15,000 buyers moves you to click "buy"; the same 4.5 from a single buyer does not. The number of independent opinions is doing the work.
- Movie ratings. An IMDb score is thousands of people watching separately and rating separately, collapsed into one number that tracks "what people collectively feel" surprisingly well.
- Elections. A democracy assumes that if most people back a choice, that choice is probably reasonable. One vote each, aggregated.
There's an old anecdote, a couple hundred years old by some accounts, of a fair where a host put an animal on stage and asked the crowd to guess its weight, prize to whoever got closest. No single guess was exact, but the average of everyone's guesses landed remarkably close to the true weight. Somehow the crowd, collectively, knew, and The Wisdom of Crowds by James Surowiecki is the usual pointer for reading more on why.
Ensemble learning is this fact turned into an algorithm: gather many models, ask each one, and decide from their combined answer.
3. The Prediction Step
Training differs a lot between ensemble types and is deferred to the later posts. The prediction step, though, is the same everywhere and is worth pinning down now.
Say you have a trained ensemble of five base models. A new data point arrives, for example a student with a known CGPA and IQ, and the question is whether they get placed.
Classification. Hand the point to all five models. Suppose three say "placed" and two say "not placed." The ensemble takes the majority vote: "placed." Whatever class most base models predict is the ensemble's prediction.
Regression. Same setup, but now each model outputs a number: 8.1, 3.2, 7.5, 6.9, 7.1 lakh. The ensemble takes the mean. Nothing else changes.
4. The One Rule: Base Models Must Differ
An ensemble of five identical models is just one model asked five times. For the crowd to be wise, its members have to bring different information.
The KBC analogy again: if every person in the audience is a software developer, "ask the audience" only helps on computer science questions and is useless on everything else. An audience with a chartered accountant, a civil engineer, a doctor, a politician, and a philosopher covers far more ground; whatever the question, someone probably knows.
There are two ways to manufacture that difference between base models:
- Different algorithms, same data. Model 1 is linear regression, model 2 is an SVM, model 3 is a decision tree, all trained on the same dataset. They disagree because they see the data through different assumptions.
- Same algorithm, different data. All models are, say, decision trees, but each is trained on a different subset of the rows. They disagree because they learned from different examples.
A third option is to combine both. These two levers are exactly what separate the four ensemble families below.
5. The Four Families
| Family | How base models differ | How outputs combine |
|---|---|---|
| Voting | different algorithms, same data | plain majority vote / mean |
| Stacking | different algorithms, same data | a second model learns how much to trust each base model |
| Bagging | same algorithm, different random subsets of data | plain majority vote / mean |
| Boosting | same algorithm, trained in sequence | each model fixes the previous model's mistakes |
Voting
The simplest. Pick a few different algorithms, say KNN, logistic regression, and a decision tree. Train all of them on the same dataset. To predict, pass the new point to all three and take the majority vote (classification) or the mean (regression). All base models count equally. The diversity comes entirely from using different algorithms.
Stacking
Voting with one change: instead of every model getting an equal vote, a separate machine learning model sits on top and learns weights for the base models, based on which ones tend to be right. Analogy: normal democracy gives everyone one vote; stacking is a democracy that first works out whose judgement to weight more heavily. The meta-model is trained on the base models' predictions (plus the true labels) and outputs the final answer.
Bagging
Here the base models are all the same algorithm. The difference comes from the data. Given 1,000 training rows and a target of 500 rows per model, you draw 500 rows at random with replacement (a "bootstrap sample"), train a model on them, put the rows back, and draw another 500 for the next model. Each model ends up trained on a different slice, so each learns something slightly different. Predict by majority vote / mean, same as voting. The name is short for bootstrap aggregating.
Random Forest is the special case of bagging where every base model is a decision tree. A forest is a collection of trees; that is where the name comes from. It is one of the most useful algorithms in practice and gets its own posts.
Boosting
Boosting also uses the same algorithm repeatedly, but in sequence rather than in parallel. The first model trains on the data and notes which rows it got wrong. Those mistakes are passed to the second model, which is told to pay extra attention to them; it improves on those rows but makes its own errors, which pass to the third model, and so on. Each model in the chain is weak on its own, but the running combination keeps shrinking the overall error. The famous names here are AdaBoost, Gradient Boosting, and XGBoost, the last of which dominates tabular Kaggle competitions.
6. Why Aggregation Works
Two pictures give the intuition.
Classification. Train several unpruned decision trees, each on its own bootstrap sample. Individually their decision boundaries are jagged and they disagree with each other, each one has memorised the quirks of its particular sample. Take a majority vote across many of them and the noise in any single boundary gets outvoted, leaving a cleaner boundary than any one tree drew.
Regression. Train many unpruned decision-tree regressors, each on its own noisy sample of the same underlying curve. Each one is a wild staircase that chases the noise. Average them and the individual overshoots and undershoots cancel, and the mean curve tracks the true function closely.
In both cases the ensemble is not doing anything clever per model; it is letting uncorrelated errors cancel.
7. Benefits
- Better performance. The headline reason. Most of the time, an ensemble beats the best single model you had.
- Bias and variance control. The central struggle in applied ML is that lowering one usually raises the other, they trade off against each other rather than both improving together. Ensembles help push both down at once, which single-model tuning usually can't. Wrap one around a low-bias, high-variance model (a deep, unpruned decision tree) and it keeps the low bias while pulling the variance down. Wrap one around a high-bias, low-variance model (logistic or linear regression) and it can pull the bias down while leaving the variance where it was. Exactly which family does which, and why, is worth its own detailed look once each family has been covered individually.
- Robustness. An ensemble's predictions move less when the input data shifts. This is closely related to the variance point, but in practice it shows up as a model that does not fall apart on slightly different data.
8. The Cost
There is one real disadvantage: compute. Where you used to train one model, you now train many, so training is slower and heavier. Ensembles are worth it because the accuracy gain usually pays for the extra cost, but the trade is real.
9. When to Use It
Treat an ensemble as the last step. Do the data cleaning, the preprocessing, the feature engineering, build and tune a model, evaluate it, and then wrap an ensemble around it. Most of the time the result improves.
If you work as a data scientist, use ensembles on real projects. In Kaggle-style competitions they are effectively mandatory; top entries lean on them heavily, and XGBoost in particular became famous largely because of how well it did in Kaggle competitions.
One more practical note from the video: on small to medium tabular datasets, well-built ensemble methods very often beat deep learning, so this block of the series is worth learning well before reaching for a neural network.
10. What's Next
The rest of this block works through the families one at a time: voting first, then bagging and random forest, then the boosting algorithms, and finally stacking.
