Machine LearningEnsemble Learning

What is the difference between bagging and boosting?

Question 290 of 303 · Updated

On this page

Bagging trains multiple models independently on different bootstrap samples and combines their predictions. Boosting trains models sequentially, with each new learner trying to improve the current ensemble. Both are ensemble-learning techniques, but they create diversity and combine models in different ways.

A simple way to remember the distinction:

  • Bagging: build models in parallel on resampled datasets, then average or vote.
  • Boosting: build models in sequence, where later learners address errors or remaining loss from earlier stages.

The difference affects bias, variance, training time, robustness, and the kinds of problems each method handles well.

1. What is bagging?#

Bagging stands for Bootstrap Aggregating. It was introduced by Leo Breiman as a way to improve predictors by creating multiple versions of a model and aggregating their outputs.

The procedure is:

  1. Start with a training dataset containing observations.
  2. Draw several bootstrap datasets by sampling observations with replacement.
  3. Train one base model independently on each bootstrap dataset.
  4. Combine their predictions:
  • Regression: average the predictions.
  • Classification: use majority or probability voting.

Because sampling is with replacement, a bootstrap dataset can contain the same training observation more than once, while some original observations may be absent from that sample.

Numerical example#

Suppose a dataset has five training records:

LaTeX

Three bootstrap samples of the same size might be:

LaTeX

Train one model on each sample. For a new house, suppose their predicted prices are:

LaTeX

The bagged regression prediction is:

LaTeX

The combined prediction is less dependent on the quirks of any one sampled training set.

For classification, if five independently trained models predict:

LaTeX

majority voting predicts Yes.

Why can bagging help?#

Some learning algorithms are unstable: a small change in training data can produce a noticeably different fitted model. Decision trees are a common example. Bootstrap samples create different versions of the training data, and aggregation can smooth out variation among the resulting predictors.

Bagging is therefore especially associated with variance reduction. It does not guarantee better performance for every base learner; it is most useful when the learner's predictions vary meaningfully across samples.

2. What is boosting?#

Boosting combines a sequence of learners into an additive model. The next learner is trained in a way that improves the current ensemble rather than independently repeating the original training task.

A general process is:

  1. Initialize a simple prediction.
  2. Fit a base learner.
  3. Measure errors or the remaining loss.
  4. Train another learner to address what the current ensemble has not captured.
  5. Add the new learner's contribution to the ensemble.
  6. Repeat for a chosen number of stages or until a stopping condition is met.

The exact correction mechanism depends on the boosting algorithm.

  • AdaBoost changes the weights of training examples, increasing the influence of examples that earlier learners misclassified.
  • Gradient boosting fits each new learner to the negative gradient of the loss function. With squared-error regression, this corresponds to fitting residuals.

The final model is usually a weighted sum of the learners:

LaTeX

Here, is the learner added at stage , and controls its contribution. Some algorithms use a common learning rate or additional learner-specific weights.

Numerical intuition#

Suppose actual delivery times are:

LaTeX

The current model predicts:

LaTeX

The residuals are:

LaTeX

A gradient-boosting regression tree can be trained to predict these residuals. Its output is then added, usually scaled by a learning rate, to the current model. The ensemble is updated to reduce the remaining error.

The new learner is not simply another independent model whose prediction is averaged with all the others. It is added as a correction to the current ensemble.

3. The main differences#

Training strategy#

  • Bagging: base models are trained independently on different bootstrap samples. They can generally be trained in parallel.
  • Boosting: models are trained sequentially. Each stage depends on the current ensemble, so the sequence is inherently less parallelizable.

Data used by each learner#

  • Bagging: each learner receives a bootstrap-resampled version of the original training set.
  • Boosting: learners work on the training data with an algorithm-specific change in emphasis, such as sample weights or pseudo-residual targets. Not every boosting method literally resamples the data or increases weights on misclassified rows.

How predictions are combined#

  • Bagging: typically averages regression predictions or takes a majority/probability vote for classification.
  • Boosting: builds an additive prediction, often using weighted learner outputs and a learning-rate coefficient.

Primary statistical effect#

  • Bagging: commonly reduces variance by averaging unstable predictors.
  • Boosting: progressively improves the fit by reducing the loss, often helping reduce bias; depending on the algorithm and data, it can also affect variance.

These are useful tendencies, not absolute guarantees. The actual bias-variance behavior depends on the base learner, data, loss, regularization and tuning.

Sensitivity to noise and outliers#

  • Bagging: averaging can reduce the influence of an individual model's unusual prediction. It does not automatically remove noisy or mislabeled observations.
  • Boosting: some variants may repeatedly emphasize difficult observations. If those observations are mislabeled or extreme outliers, the model can spend too much capacity trying to fit noise. Regularization, robust losses and early stopping can help.

Computation#

  • Bagging: independent model fits make parallel training straightforward, although prediction may require evaluating many models.
  • Boosting: later learners depend on earlier stages, so training is more sequential. Learning rate, number of estimators and tree complexity influence the speed/accuracy trade-off.

4. Bias and variance: why the distinction matters#

Prediction error can be understood through the familiar bias-variance-noise decomposition, under suitable assumptions.

  • Bias describes systematic error from a model that is too simple or makes restrictive assumptions.
  • Variance describes how much the fitted model changes when the training sample changes.
  • Irreducible noise comes from randomness or missing information in the problem itself.

Bagging averages models trained on perturbed samples. If their errors are not perfectly correlated, averaging can reduce variance.

Boosting builds an additive model stage by stage. Each new component attempts to capture patterns that the current ensemble has not learned, which can reduce systematic underfitting. But adding too many or overly complex learners can overfit, particularly when the data are noisy.

Neither method is inherently “always lower bias” or “always lower variance.” Evaluate both on validation data rather than relying only on the textbook tendency.

A Random Forest is a tree-ensemble method that combines two sources of randomness:

  1. Each tree is trained using a bootstrap sample of the training observations (in the common bootstrap configuration).
  2. At each split, the tree considers a random subset of available features.

The trees are trained independently and their outputs are aggregated. This makes Random Forest a prominent bagging-based method, with additional feature randomness that reduces correlation among trees.

Random Forest is not identical to every bagging implementation. Bagging is a general ensemble strategy that can use many types of base estimators; Random Forest specifies decision trees and randomized feature selection.

6. Common algorithms#

Bagging-based methods

  • Bagging Classifier and Bagging Regressor
  • Random Forest
  • Extra Trees are also tree ensembles based on additional randomization; they are related but should not be treated as exactly the same algorithm as bootstrap bagging.

Boosting-based methods

  • AdaBoost
  • Gradient Boosting
  • XGBoost
  • LightGBM
  • CatBoost

These boosting implementations differ in objective functions, tree construction, regularization, missing-value handling, categorical-feature support and computational optimizations. They all build an additive sequence of learners, but their detailed training procedures are not identical.

7. When should you use bagging?#

Consider bagging when:

  • Your base learner is unstable and has high variance.
  • You want to reduce sensitivity to changes in the training sample.
  • Independent model training and parallel computation are useful.
  • You want a robust tree-based baseline with relatively little feature engineering.
  • You prefer averaging several models rather than fitting a sequence of corrections.

Random Forest is often a strong starting point for tabular classification or regression, though it should still be compared against simpler baselines and other candidate models.

8. When should you use boosting?#

Consider boosting when:

  • A single model underfits important patterns.
  • You want to improve predictive performance through staged corrections.
  • You have structured/tabular data and can tune the model carefully.
  • You can validate the number of boosting rounds, learning rate and tree complexity.
  • You can monitor overfitting and the impact of noisy or mislabeled examples.

Gradient-boosted tree libraries such as XGBoost, LightGBM and CatBoost are widely used for tabular prediction tasks. Their performance depends on appropriate validation, regularization and tuning; they are not automatically superior to Random Forests.

9. Practical comparison example#

Imagine building a model to predict whether a customer will repay a loan.

With bagging / Random Forest:

  • Create multiple bootstrap samples of the customer dataset.
  • Train a separate decision tree on each sample, using randomized feature subsets in Random Forest.
  • Each tree predicts repayment or default.
  • Aggregate the tree predictions by voting or probabilities.

The goal is to make the final prediction less sensitive to any one tree's training sample.

With boosting:

  • Train an initial weak tree.
  • Identify where the current ensemble's predictions have high loss.
  • Fit another tree to emphasize those errors or the negative gradient of the loss.
  • Add the new tree's contribution to the ensemble.
  • Repeat until validation performance stops improving or another stopping rule is reached.

The goal is to improve the ensemble in successive stages.

For a real loan-risk model, also check class imbalance, calibration, fairness across relevant groups, stability over time, leakage, and the cost of false approvals versus false declines. Accuracy alone is not sufficient for model selection.

10. Can bagging and boosting be used together?#

Yes, but they are distinct ensemble strategies rather than mutually exclusive categories of every possible model. A system can use different ensemble methods at different levels, or combine their predictions in a separate voting or stacking model.

For example, you could train a Random Forest and a gradient-boosted tree model, then evaluate a calibrated blend of their probabilities on held-out data. This is a separate ensemble layer; it does not make the individual Random Forest a boosting algorithm.

Avoid adding complexity without evidence. Compare the blended model with each individual model using the same validation protocol.

11. Key takeaway#

Bagging reduces model instability by training independent models on bootstrap samples and aggregating their predictions. Boosting builds a model sequentially, where each new learner improves the current ensemble by addressing errors or remaining loss.

Remember:

  • Bagging: bootstrap, parallel learners, averaging/voting, often variance reduction.
  • Boosting: sequential learners, staged correction, additive combination, often improved fit and reduced bias.
  • Random Forest is a well-known bagging-based method.
  • AdaBoost and gradient-boosted trees are boosting methods.

Interview answer: Bagging trains multiple independent models on bootstrap samples and combines their predictions, usually to reduce variance. Boosting trains weak learners sequentially, with each new learner focusing on errors or residual loss from the current ensemble, and combines them additively. Bagging is naturally parallelizable; boosting has sequential dependencies. Random Forest is a common bagging-based algorithm, while AdaBoost, XGBoost, LightGBM and CatBoost are boosting algorithms.

Related questions

Explore other topics:Deep LearningMLOps