October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

What Is Bootstrap Aggregation? How Bagging Makes Machine Learning Models More Robust

Bagging trains multiple models on bootstrap samples and aggregates their predictions. See how it reduces sensitivity to training data and where its limits lie.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Bootstrap aggregation, usually called bagging, trains multiple copies of a model on bootstrap samples of the same training set, then combines their predictions. Because each sample is drawn with replacement, some examples appear more than once and others are left out. Combining the resulting models can reduce prediction variance—especially when the underlying model is sensitive to changes in its training data—but it does not guarantee better accuracy.

What is bagging in machine learning?

Bagging is short for bootstrap aggregating. It is an ensemble method: instead of relying on one fitted predictor, it fits several predictors of the same kind using resampled versions of the training data, then aggregates their outputs. Leo Breiman introduced the method in “Bagging Predictors” in 1996. Breiman’s paper and abstract describe averaging numerical predictions and using plurality voting for classification.

As an Amazon Associate I earn from qualifying purchases.

The bootstrap is the resampling step. A bootstrap sample is drawn from the original cases with replacement, so a case can be selected more than once in one sample while another case may not be selected at all. Repeating this process creates training sets that differ from one another, even though they come from the same original data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How does bagging work?

  1. Start with a training set. This is the set of labeled examples used to fit the models.
  2. Draw bootstrap samples. Make multiple samples, typically of the same nominal size as the original set, by selecting cases with replacement.
  3. Fit one estimator per sample. Train a separate copy of the chosen model on each resampled set.
  4. Combine predictions. For a numerical target, the usual approach is to average predictions. For a class label, the original formulation uses plurality voting: choose the class receiving the most votes.

Some classifiers instead combine class probabilities. For example, scikit-learn’s random-forest documentation describes averaging probability estimates across trees. The aggregation rule depends on the estimator and implementation; the underlying idea is to combine outputs from models trained on different samples. See scikit-learn’s ensemble-methods documentation.

Why can bagging make predictions more robust?

Bagging is primarily a variance-reduction technique. A model has high variance when modest changes to its training data can lead to substantially different fitted models or predictions. Decision trees are a common example: small changes in the examples available to a tree can alter its splits and structure. Training trees on different bootstrap samples produces different fits; averaging or voting can soften errors that are specific to any one sample.

In this context, robustness means less sensitivity to which particular training examples happened to be observed. It does not mean immunity to noisy labels, biased data, distribution changes, or poor feature choices. As Breiman put it, “The vital element is the instability of the prediction method.” The quotation appears in his 1996 paper, “Bagging Predictors”.

Rank #2
Sale
Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems
  • Use scikit-learn to track an example ML project end to end
  • Explore several models, including support vector machines, decision trees, random forests, and ensemble methods
  • Exploit unsupervised learning techniques such as dimensionality reduction, clustering, and anomaly detection
  • Dive into neural net architectures, including convolutional nets, recurrent nets, generative adversarial networks, autoencoders, diffusion models, and transformers
  • Use TensorFlow and Keras to build and train neural nets for computer vision, natural language processing, generative models, and deep reinforcement learning

If resampling barely changes the base estimator, the models will tend to make similar predictions, leaving less variation for aggregation to reduce. Bagging is therefore especially useful with unstable, flexible learners, such as fully developed decision trees. It is not a universal accuracy boost: the scikit-learn guide frames variance reduction as the main goal, not a guarantee that every metric improves. Bagging also does not inherently remove bias or prevent all overfitting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Bagging and related ensemble methods

These methods all combine estimators, but differ in how they create variation or build the ensemble.

Method How it differs What that means
Bagging Samples training cases with replacement. Bootstrap resampling followed by aggregation.
Pasting Samples cases without replacement. Similar sample aggregation, but the samples are not bootstrap replicates.
Random subspaces Uses random subsets of features. Variation comes from which features each estimator sees.
Random patches Uses subsets of both cases and features. Variation comes from both dimensions.
Boosting Builds estimators sequentially. A different ensemble strategy; scikit-learn contrasts boosting’s usual weak learners with bagging’s strong, complex learners.
Random forest In scikit-learn’s documented implementation, combines bootstrap samples with random feature selection at tree splits. A particular tree-ensemble approach related to bagging, not a synonym for bagging in general.

The distinctions above follow the scikit-learn guide to ensemble methods. A random forest uses bagging-like resampling but adds feature randomness, so not every bagging model is a random forest.

Out-of-bag evaluation: useful estimate, not a replacement for validation

Because a bootstrap sample leaves some training cases out, those excluded cases are called out-of-bag (OOB) for that fitted estimator. Across the ensemble, OOB predictions can be used to estimate generalization performance. In scikit-learn, the bagging estimators expose this option through oob_score=True when the sampling setup leaves cases out. The documentation presents OOB scoring as an estimate; it should not be treated as a reason to ignore an evaluation design appropriate to the task, such as a held-out test set or cross-validation. Check the current scikit-learn ensemble documentation for supported options and API details.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Using bagging in scikit-learn

Scikit-learn provides BaggingClassifier and BaggingRegressor. Their controls include the number or fraction of estimators’ training samples and features, and whether sampling uses replacement. The exact parameter names and behavior can change between releases, so consult the current official ensemble documentation before relying on a particular setting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a practical workflow, choose a base estimator that is likely to vary meaningfully across samples, fit and tune the ensemble using validation suited to your data, and compare it with a single-estimator baseline. Use OOB scoring as one available estimate when its conditions are met, not as proof that the ensemble will perform well on future data.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.