Ensemble Learning: Bagging, Boosting, Stacking and Voting Explained
Ensemble learning combines the predictions of several models so that their individual errors partly cancel out, which usually gives better accuracy and more stable results than any single model. The four main methods are bagging (many models on resampled data, such as random forests), boosting (models trained in sequence to fix earlier mistakes, such as XGBoost), stacking (a meta-model learns how to combine base models) and voting (a simple vote or average). On TensorTurn you can ask for any of these in a notebook, or run ensemble mode to train several diverse models in parallel across your own connected machines.
Why ensembles work
Every model makes errors. If two models make the same errors, combining them adds nothing. If their errors are different and only partly correlated, averaging their predictions lowers the variance of the combined prediction, and a sequential method like boosting can also lower bias. The key ingredient is diversity: different training samples, different random seeds, different features or different algorithms. A combination of five near-identical models is barely better than one.
Bagging vs boosting vs stacking vs voting
| Method | How it works | Mainly reduces | Examples | When to use |
|---|---|---|---|---|
| Bagging | Train many models in parallel on bootstrap samples of the data, then average or vote | Variance | Random forest, bagged decision trees, Extra Trees | High-variance models that overfit, such as deep decision trees |
| Boosting | Train models in sequence, each focusing on the errors of the ones before | Bias, and variance with regularisation | XGBoost, LightGBM, CatBoost, AdaBoost | Tabular data where you want top accuracy; the default for most structured problems |
| Stacking | Train diverse base models, then fit a meta-model on their out-of-fold predictions | Both, by learning which model to trust when | Logistic regression over XGBoost, random forest and a neural net | Squeezing out the last gains once single models are tuned |
| Voting / averaging | Combine predictions directly by majority vote, averaged probabilities or averaged values | Variance | Soft-voting classifier, averaged regressors, multi-seed neural nets | Quick wins from models you already have; parallel training across machines |
Hard vs soft voting
Hard voting takes the class predicted by the most models. Soft voting averages each model's predicted probabilities and picks the class with the highest average. Soft voting is usually better because it uses each model's confidence, but it needs models whose probabilities are reasonably calibrated. For regression the equivalent is simply averaging the predicted values, optionally weighted by each model's validation score.
Stacking without leaking
Stacking has one serious trap. If the meta-model is trained on predictions the base models made on data they were trained on, those predictions are overconfident and the meta-model learns to trust them too much. The fix is to generate out-of-fold predictions: split the training data into k folds, train each base model on k-1 folds, predict the held-out fold, and use those predictions as the meta-model's features. Keep the test set completely untouched until the very end.
When ensembles are not worth it
- The base models are too similar. Five gradient boosting models with the same settings add little; vary seeds, features or algorithms.
- Latency or memory is tight. Serving ten models costs roughly ten times the compute of one; consider distilling the ensemble into a single model.
- Interpretability is required. An ensemble is harder to explain than a single tree or linear model, which matters in regulated decisions.
- The data is the bottleneck. Leakage, noisy labels or missing signal cannot be fixed by combining models; clean the data first.
- Gradient boosting is already an ensemble. Bagging a well-tuned XGBoost model rarely helps much; diversity from a different model family helps more.
Ensemble mode across your own machines
Ensembles are naturally parallel: each member can train independently. TensorTurn uses this in its distributed training feature. When you connect two or more of your own machines, you can pool them into one run in ensemble mode. Each member trains with its own random seed, so the models come out diverse, a live leaderboard shows each member's score, and the members' predictions are combined by soft voting or averaging. Because members never need to talk to each other, slower or faster machines simply take more or less of the work.
The alternative, fused mode, shards the rows across machines and periodically averages model weights to produce one merged model instead of a committee. Choose ensemble mode when accuracy matters most and you can afford to serve several models; choose fused mode when you need a single model or the dataset is too large for one machine.
How to build an ensemble on TensorTurn
- Upload your data and run the health check, fixing leakage and duplicates first so every member learns from clean data.
- In chat, ask for the ensemble you want, for example: 'Train XGBoost, LightGBM and a random forest, then stack them with logistic regression using 5-fold out-of-fold predictions and compare against the best single model.'
- TensorTurn writes and runs the notebook with scikit-learn, XGBoost, LightGBM, PyTorch or Keras, on a cloud GPU or free on your own GPU.
- To spread an ensemble across hardware, connect your machines with one command each and launch a distributed run in ensemble mode.
- Compare the reported metrics of the ensemble with the best single model, and keep the ensemble only if the gain justifies the extra serving cost.
Frequently asked questions
What is ensemble learning in simple terms?
Ensemble learning trains several models and combines their predictions, by voting, averaging or a learned combiner, so the group is more accurate and stable than any single member. It works best when the models make different kinds of mistakes.
What is the difference between bagging and boosting?
Bagging trains models independently on random resamples of the data and averages them, which mainly reduces variance; random forest is the classic example. Boosting trains models one after another, each correcting the previous errors, which reduces bias; XGBoost and LightGBM are popular examples.
Is stacking better than voting?
Stacking can beat simple voting because the meta-model learns which base model to trust in which situation, but it is more complex and easy to overfit. Always build it from out-of-fold predictions, and compare it against plain soft voting before keeping it.
Is XGBoost an ensemble method?
Yes. XGBoost is a gradient boosting library, and boosting is an ensemble method: the final model is a sum of many decision trees, each trained to correct the errors of the trees before it.
Can I train an ensemble across multiple computers?
Yes. With TensorTurn you can connect two or more of your own machines and run a distributed job in ensemble mode, where each machine trains diverse members in parallel and their predictions are combined by voting or averaging.