Bagging and boosting are the two main families of ensemble learning, and the core difference is that bagging trains its base models independently in parallel, while boosting trains them sequentially, with each new model focusing on the mistakes of the previous ones. This single architectural difference drives everything else: how they reduce error, how they handle noise, and when you should choose one over the other.
Formula
The calculator above estimates how much bagging reduces the error rate of a set of base models. The effective error is approximated by:
E_eff = E × (1 − (1 − ρ) × (1 − 1/N))
Where:
- E = average error rate of a single base model (as a decimal or percentage)
- ρ = correlation between the errors of different base models (0 = completely independent, 1 = identical errors)
- N = number of base models
This is a simplified version of the error decomposition formula. The key insight is that when errors are independent (ρ = 0), the error drops roughly as 1/N. When errors are perfectly correlated (ρ = 1), bagging gives no improvement at all.
Worked Example
Using the default values: 100 models, a base error rate of 40%, and a correlation of 0.5. First, compute the reduction factor:
1 − (1 − 0.5) × (1 − 1/100) = 1 − 0.5 × 0.99 = 1 − 0.495 = 0.505
Then multiply by the base error: 40% × 0.505 = 20.2%.
The effective error is 20.2%, which is a reduction of (40 − 20.2) / 40 × 100 = 49.5% compared to a single model. This matches the calculator output.
Background: Why Ensembles Work
An ensemble is a set of models whose predictions are combined (by voting or averaging) to produce a final output. The reason ensembles work is the wisdom of the crowd: if each model makes different errors, then the majority vote or average can cancel those errors out. The two main ways to create diversity are:
- Bagging (Bootstrap Aggregating): Each model sees a random sample of the training data (with replacement). Models are trained independently and in parallel.
- Boosting: Each model sees the full training data, but the data is reweighted after each model so that previously misclassified examples get more weight. Models are trained sequentially.
The fundamental difference is the parallel vs sequential training process, which leads to different error profiles.
How Bagging Works
Bagging, introduced by Leo Breiman in 1996, follows these steps:
- Create N bootstrap samples (random samples with replacement) from the training data.
- Train a base model (e.g., decision tree) on each sample.
- For regression, average the predictions; for classification, take a majority vote.
The key is that each model is trained independently, so they can be trained in parallel on different machines. The diversity comes from the different data samples. Because each sample is slightly different, the models make different errors, and averaging reduces the variance.
The most famous bagging algorithm is Random Forest, which adds an extra layer of randomness by choosing a random subset of features at each split. This decorrelates the trees even more, leading to better variance reduction.
How Boosting Works
Boosting, which has its roots in the theoretical work of Schapire and Freund in the 1990s, works differently:
- Train a weak model on the full dataset with equal weights.
- Increase the weights of misclassified examples.
- Train the next model on the reweighted data.
- Repeat for T models, then combine them with weighted voting.
Each new model is forced to focus on the hard cases that previous models got wrong. This sequential process means that boosting cannot be parallelized in the same way as bagging. The most popular boosting algorithms are AdaBoost (Adaptive Boosting) and Gradient Boosting (including XGBoost, LightGBM, and CatBoost).
Boosting reduces both bias and variance, but it is more prone to overfitting if the data is noisy, because it aggressively chases after every misclassified point.
Key Differences: Variance vs Bias
The most important practical difference is the type of error they reduce:
- Bagging reduces variance: It averages out the fluctuations caused by different training samples. It is ideal for high-variance models like deep decision trees.
- Boosting reduces bias: It sequentially improves the model’s fit to the data, so it is ideal for weak models that underfit (like shallow trees).
In practice, boosting often achieves higher accuracy than bagging on clean datasets, but bagging is more robust to noise and outliers. If your data has a lot of label noise, bagging will usually generalize better.
How to Choose Between Bagging and Boosting
There is no universal rule, but these guidelines help:
- Use bagging when: your base models are complex and overfit (e.g., deep trees), your dataset is noisy, or you need to train models in parallel for speed.
- Use boosting when: your base models are weak (e.g., shallow trees), you have clean data, and you want the highest possible accuracy, even if it takes longer to train.
- Consider the data size: Boosting often performs better on small to medium datasets; bagging (especially Random Forest) scales well to very large datasets.
It is common to try both and use cross-validation to decide. In many competitions, gradient boosting (XGBoost, LightGBM) wins on tabular data, but Random Forest is a strong, robust baseline.
Common Problems and Misconceptions
One common misconception is that boosting is always better. That is not true. Boosting can overfit noisy data because it keeps focusing on outliers. Bagging is more stable.
Another issue is correlation: if the base models in bagging are too similar (e.g., using the same features), the variance reduction is limited. Random Forest solves this by feature subsampling.
For boosting, the main problem is sequential training time. You cannot easily parallelize it, though modern implementations like XGBoost use histogram-based methods and parallel tree building to speed things up.
Finally, both methods require tuning: bagging needs the number of models and feature subsampling; boosting needs learning rate, number of models, and tree depth.
Frequently Asked Questions
Which is faster: bagging or boosting?
Bagging is generally faster because models are trained in parallel. Boosting is sequential, so it takes longer, especially with many models. However, boosting often needs fewer models to reach good accuracy, which can offset the time.
Can boosting be parallelized?
Not the core sequential part, but modern libraries like XGBoost and LightGBM parallelize the construction of each individual tree and use efficient histogram-based splitting. Still, you cannot train the whole boosting ensemble in parallel like bagging.
What is the difference between AdaBoost and Gradient Boosting?
AdaBoost adjusts sample weights and uses weighted voting. Gradient Boosting fits each new model to the residual errors of the previous ensemble, using a gradient descent framework. Gradient Boosting is more flexible and often performs better.
When should I use Random Forest over XGBoost?
Use Random Forest when you have noisy data, need a robust baseline, or want to train quickly in parallel. Use XGBoost (or LightGBM) when you have clean data and want to squeeze out the last bit of accuracy, even if you need to tune hyperparameters carefully.
Does bagging reduce bias?
Not significantly. Bagging mainly reduces variance. Boosting reduces bias. If your model is underfitting (high bias), bagging won’t help much; boosting is the better choice.
What is the role of the learning rate in boosting?
The learning rate (shrinkage) scales the contribution of each new model. A lower learning rate requires more models but often generalizes better. It is a key hyperparameter to tune in gradient boosting.
Related
Formula used
in t | Number of models | - | 100 | 1 | 1000 in e | Base model error rate | % | 40 | 0 | 99 in d | Diversity (correlation) | - | 0.5 | 0 | 1 out eff | Effective error (bagging) | % | e * (1 - (1 - d) * (1 - 1/t)) | 2 out red | Error reduction vs single model | % | (e - eff) / e * 100 | 1
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Delete Picture Kik? How to Remove Photos
- What Happens to X Replies, DMs, and Followers After Deletion?
- Data Breaches That Shook the World
- Disable Google Assistant: Turn It Off on Android & Home
- Resin vs FDM Printers for Miniatures: Detail, Durability, Cost
- Are Networked Implants Safe? What If One Fails?