Home Knowledge Base Bagging (Bootstrap Aggregating)

Bagging (Bootstrap Aggregating) is an ensemble technique that reduces variance and overfitting by training multiple models independently on random bootstrap samples of the training data and averaging their predictions — based on the insight that while a single decision tree might overfit to noise in the training data, averaging 100 trees trained on different random subsets cancels out the individual trees' noise, producing a stable, robust predictor that is the foundation of Random Forest, one of the most successful algorithms in machine learning.

What Is Bagging?

How Bagging Works

StepProcessExample
1. BootstrapSample N with replacement from NOriginal: [1,2,3,4,5] → Sample 1: [1,1,3,4,5]
2. TrainFit independent model on each sampleTree 1 on Sample 1, Tree 2 on Sample 2, ...
3. RepeatCreate M bootstrap samples + modelsM = 100 trees trained independently
4. AggregateCombine predictionsClassification: majority vote; Regression: average

Variance Reduction

Single TreeBagged Ensemble (100 Trees)
High variance — changing one training example changes the treeLow variance — changing one example affects ~1 tree
Unstable — small data changes → very different predictionsStable — consistent predictions across data perturbations
Overfits easilyResistant to overfitting
Interpretable (one tree)Less interpretable (100 trees)

Out-of-Bag (OOB) Evaluation

Each bootstrap sample leaves out ~36.8% of the data. For each training example, ~37% of the trees never saw it during training. These trees provide honest predictions for that example — no need for a separate validation set.

from sklearn.ensemble import BaggingClassifier, RandomForestClassifier

# Generic Bagging (any base estimator)
bagging = BaggingClassifier(
    n_estimators=100, max_samples=1.0,
    bootstrap=True, oob_score=True
)
bagging.fit(X_train, y_train)
print(f"OOB Score: {bagging.oob_score_:.3f}")

# Random Forest = Bagging + Feature Subsampling
rf = RandomForestClassifier(n_estimators=100, oob_score=True)

Bagging vs Random Forest

FeatureBagging (Decision Trees)Random Forest
Bootstrap samplesYesYes
Feature subsampling per splitNo (uses all features)Yes ($sqrt{p}$ features per split)
Tree diversityFrom bootstrap onlyFrom bootstrap + feature randomization
PerformanceGoodBetter (more diverse trees)

Bagging is the foundational variance-reduction ensemble technique — demonstrating that averaging many unstable, overfitting models produces a stable, accurate predictor, serving as the theoretical basis for Random Forest, and proving the counterintuitive principle that combining many "wrong" models can produce a "right" ensemble when their errors are independent.

baggingbootstrapaggregate

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.