# Bagging (bootstrap aggregating)

> Canonical: https://skillalmanac.com/glossary/bagging | Last verified: 2026-11-25 | Index status: index-eligible

Bagging, short for bootstrap aggregating, is an ensemble method that trains several copies of the same model on random samples of the training data, drawn with replacement, then combines their predictions to reduce variance.

Also called: bootstrap aggregating, bootstrap aggregation, bagging in machine learning, bagging ensemble.

## In plain language

Bagging is a way to get steadier predictions by asking several similar models instead of one. Each model sees a different random sample of the same data, in which some rows appear twice and others are left out. Then the models vote, or their numbers are averaged. Picture asking five colleagues who each saw a slightly different set of past orders to estimate next month's demand, then taking the middle view. It smooths out the quirks of any single model. The limit is that it is aimed at variance, the way a model's results swing with the data it saw, so do not expect it to fix other kinds of error, and it takes more work to train and run because there are many models.

## Technical definition

Each base learner is fitted on a bootstrap sample, a random sample drawn from the training set with replacement, so IBM notes that individual data points can be chosen more than once. The learners train independently of one another, in parallel. For classification their predictions are combined by majority vote, and for regression they are averaged, according to IBM. The scikit-learn documentation describes bagging as building several instances of a black-box estimator on random subsets of the training set and aggregating their predictions to reduce the variance of a base estimator, such as a decision tree. It lists the variants by what is sampled: pasting draws random subsets of the samples (scikit-learn's bootstrap parameter controls replacement), random subspaces draw features, and random patches draw both. Samples left out of a bootstrap, called out-of-bag samples, can be used to estimate generalization accuracy when oob_score=True. The scikit-learn page cites Breiman, Bagging predictors, 1996.

## How it shows up when you use agents

Bagging is a classic machine-learning technique, not an agent feature, so you meet it when an agent helps you with data work. Ask a coding agent such as Claude Code or Codex to build a model on a spreadsheet and it may reach for scikit-learn, whose BaggingClassifier takes a base model and settings for how to draw the random subsets. A [random forest](/glossary/random-forest) is a closely related method: IBM calls it an extension of bagging that adds feature randomness to decision trees.

Two things matter in practice. First, bagging is described as a variance reducer. A single [decision tree](/glossary/decision-tree) can swing when the training data changes, and scikit-learn says bagging introduces randomization and builds an ensemble to reduce that variance. The scikit-learn page says bagging works best with strong, complex base models such as fully developed decision trees, whereas boosting usually works best with weak ones. Second, you still need an honest test. Evaluate on rows the ensemble did not see, which is what the [split leakage check](/skills/skill-almanac/split-leakage-check) skill audits, and use out-of-bag samples as scikit-learn describes when you cannot spare a test set.

What breaks when bagging is misunderstood: people expect it to cure every kind of error, when the sources describe it as a way to reduce variance (see [bias and variance](/glossary/bias-variance-tradeoff)), or they add models without checking that the extra cost helps. A next step is to compare the single model and the bagged one on held-out data before you keep the extra cost. See [ensemble learning](/glossary/ensemble-learning) for the wider family.

## Common confusions

- **Bagging versus boosting.** IBM notes that in bagging the weak learners are trained in parallel, while in boosting they learn sequentially, while AdaBoost-style classification raises weights on misclassified examples. Gradient boosting instead fits loss gradients; it is not defined by that reweighting rule. See [Gradient boosting](/glossary/gradient-boosting).
- **Bagging versus random forest.** A random forest is bagging of decision trees plus feature randomness, in IBM's words. Bagging itself works with any base model.
- **Bootstrap versus pasting.** In scikit-learn terms, drawing samples with replacement is bagging. Drawing them without replacement is called pasting.
- **Myth: bagging fixes any weak model.** The sources describe it as a way to reduce variance. Extra models also add training and prediction cost.

## Worked examples in this catalogue

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Checks train, validation and test files for duplicates, shared groups, time and label leakage, and prints JSON.

Why it exercises the concept: A contrast case: bagging repeats rows inside each bootstrap sample on purpose, while the files you evaluate on must not share rows with training data. The catalogue has no training skills, so this checks the evaluation side.

### [data-analysis-eda](https://skillalmanac.com/skills/skill-almanac/data-analysis-eda)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A fixed exploratory-analysis procedure and CSV profiler that keeps findings descriptive and evidenced.

Why it exercises the concept: Profile the data before you pick a model. A profile describes input spread and data issues; it does not measure estimator variance or establish whether bagging will help. Compare the fitted single model and ensemble using appropriate validation.

### [huggingface-datasets](https://skillalmanac.com/skills/huggingface/huggingface-datasets)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Reads Hugging Face datasets through the Dataset Viewer API: metadata, rows, search and filters.

Why it exercises the concept: Another contrast case: it gives you rows to sample from, which is the raw material for bootstrap samples. The catalogue has no skill that trains a bagged ensemble.

## Related terms

- [Ensemble learning](https://skillalmanac.com/glossary/ensemble-learning.md)
- [Random forest](https://skillalmanac.com/glossary/random-forest.md)
- [Gradient boosting](https://skillalmanac.com/glossary/gradient-boosting.md)
- [Decision tree](https://skillalmanac.com/glossary/decision-tree.md)
- [Bias-variance tradeoff](https://skillalmanac.com/glossary/bias-variance-tradeoff.md)
- [Overfitting](https://skillalmanac.com/glossary/overfitting.md)
- [Machine learning (ML)](https://skillalmanac.com/glossary/machine-learning.md)

## Sources

- [Ensembles: Gradient boosting, random forests, bagging, voting, stacking](https://scikit-learn.org/stable/modules/ensemble.html), scikit-learn (accessed 2026-11-24)
- [What is bagging?](https://www.ibm.com/think/topics/bagging), IBM Think (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
