Bagging Decision Trees: How Bootstrap Aggregation Works and When to Defend It

Bagging in machine learning averages trees trained on bootstrap samples to cut variance.

Bagging Decision Trees: How Bootstrap Aggregation Works and When to Defend It
Written by TechnoLynx Published on 11 Jul 2026

Bagging in machine learning (short for bootstrap aggregating) trains many copies of the same learner, each on its own bootstrap replicate of the training set, then combines them: it averages for a numerical target and takes a plurality vote for a class. It works by reducing variance, so it pays off on unstable learners such as deep decision trees, does little or slightly worse on stable ones, and cannot push a model past the accuracy the data allows. Boosting is a different idea. It builds its ensemble in sequence, and each new member depends on the ones fitted before it, while bagging fits every member independently and in parallel.

That is the short answer. What follows covers why the variance reduction runs out, what the out-of-bag estimate is actually worth, how bagged trees differ from a random forest, and the question regulated teams care about most: when a bagged ensemble can be defended in a model-risk review, and when a single tree is the more honest choice.

How a Bootstrap Sample Is Drawn, and Why with Replacement

A bootstrap sample for bagging contains N cases drawn at random, with replacement, from a training set of N cases, so any one row may appear several times or not at all. Repeat that draw B times and you have B slightly different training sets, each of which grows one tree.

Drawing N rows without replacement from N rows would just return the original set. For a deterministic learner such as C4.5, identical inputs mean identical trees, and an ensemble of identical members gains nothing. Sampling with replacement gives every tree a different training set, and combining classifiers only pays when they disagree.

The arithmetic also gives each tree a held-out test sample. A given row is missed by one draw with probability (1 − 1/N), so it is missed by all N draws with probability (1 − 1/N)^N, which tends to e⁻¹, or roughly 37%. Each tree therefore never sees about 37% of the training rows. Those rows are its out-of-bag sample.

Drawing without replacement is a legitimate variant. When the subsets are random samples of rows drawn without replacement the method is called pasting, and subsampling often gives results similar to the bootstrap with lighter computation and weaker theoretical assumptions.

Why Bagging Reduces Variance More than Bias

Prediction error splits into squared bias, variance and irreducible noise. More complex models usually lower bias but raise variance. A fully grown decision tree sits at the high-variance end. Its splits are hard threshold decisions, the kind of decision that makes trees unstable. Averaging trees grown on different bootstrap samples smooths those hard decisions, which is why bagging reduces variance and mean squared error for trees. Bias is largely untouched: the averaged tree aims at roughly the same target as a single tree.

Bagging helps unstable base learners, not stable ones. Breiman’s original paper states the condition directly: if perturbing the learning set can change the fitted predictor substantially, bagging can improve accuracy. He listed neural networks, classification and regression trees, and subset selection in linear regression as unstable, and k-nearest neighbours as stable. On a stable procedure bagging can slightly degrade performance, and there is a crossover point between instability and stability where it stops helping and starts hurting. Among MARS, projection pursuit regression and regression trees, bagging improved decision trees the most.

Does Bagging Prevent Overfitting?

Bagging reduces overfitting by reducing variance, and scikit-learn’s documentation says it works best with strong, complex models such as fully grown trees. If the single tree is already close to the best accuracy the data supports, no amount of bagging improves it much.

The variance story is also not the only explanation on record. Grandvalet (2004) presents experimental evidence that bagging stabilises prediction by equalising the influence of individual training examples, and attributes bagging’s occasional deteriorations to highly influential bad examples, in settings where the usual variance argument is at best questionable. In our view, that is the more useful framing when a bagged model underperforms: look at a small number of dominant, possibly mislabelled rows before blaming the ensemble size.

Correlated Trees Put a Ceiling on Bagging

Averaging B estimators, each with variance σ² and pairwise correlation ρ, gives an ensemble variance of ρσ² + (1 − ρ)σ²/B. More trees shrink only the second term. The first term, ρσ², stays wherever the correlation leaves it.

Take the two extremes to see what that means, without plugging in any measured values. If the trees were independent (ρ = 0), variance would fall as σ²/B and keep falling with every tree added. If they were identical (ρ = 1), variance would stay at σ² regardless of B. Bootstrap samples are very similar, so trees grown on them are often similar and highly correlated, and an average of similar trees is more robust but not much better than one tree.

That ceiling is what random forests address by attacking ρ directly (more on that below).

Out-of-Bag Error: A Free Validation Estimate with Known Biases

Each training row is out of bag for roughly a third of the trees, so you can predict it using only those trees and compare the prediction with its true label. Averaged over all rows, that gives the out-of-bag (OOB) estimate of generalisation error, with no extra models to fit. Breiman (1996) found OOB estimates remarkably accurate and nearly unbiased in classification. A 2025 replication study across 100 random seeds found the mean of OOB-based diagnostics robust to how the bootstrap’s distinct-sample count varies, which supports the practical view that the classical bootstrap is good enough for OOB estimation in tree ensembles.

Can OOB error stand in for a separate validation set? Often, with three caveats.

First, OOB predictions use only about a third of the trees, so with a small ensemble they overestimate the error of the full ensemble. Breiman (2001) notes that you need to run past the point where test error converges to get unbiased OOB estimates. With very few estimators, some rows are never left out at all, and scikit-learn’s oob_decision_function_ can then contain NaN.

Second, OOB error overestimates the true error in specific data regimes. Janitza and Hornung (PLOS ONE, 2018) found the overestimation largest in balanced classes with small samples, many predictors, weakly correlated predictors and weak effects, and almost negligible at n = 1,000 against large at n = 20. The mechanism is that bootstrap samples drawn from balanced data come out unbalanced by chance, and the trees for which a row is out of bag lean towards the other class. In their settings with metric predictors, stratified subsampling with class-proportional fractions largely removed the bias at no extra cost. The same paper warns that this bias can mislead parameter tuning when OOB error is used to choose mtry.

Third, cross-validation is not automatically cleaner. Bylander (2002) found OOB estimates and 10-fold cross-validation performed similarly on two-class data, and both were biased. Scikit-learn’s documentation calls OOB estimates usually very pessimistic and recommends cross-validation unless it is too slow.

OOB error is a good estimate on large datasets and biased upward on small, balanced ones. For anything a reviewer will rely on, we would report it alongside a stratified cross-validation or a genuine holdout rather than instead of one. Choosing which evaluation metrics and explanations to report is a separate decision from how you estimate them.

Boosting vs Bagging in Machine Learning

The two methods differ in how members are built, which error term they target and how they behave on noisy labels.

  Bagging Boosting
Construction Parallel and independent; resampling does not depend on earlier members Sequential; each member focuses on examples earlier members got wrong
Error it mainly reduces Variance Bias as well as variance
Natural base learner Strong, complex models such as fully grown trees Weak models such as shallow trees or stumps
Versus a single classifier Almost always more accurate Can greatly outperform it, or show zero gain or a loss on some datasets
Under label noise Error does not rise as the ensemble grows Error may rise as the ensemble grows; AdaBoost concentrates weight on mislabelled rows

Dietterich (2000) found that with substantial classification noise, bagging was much better than boosting. Opitz and Maclin draw a general conclusion for decision trees and neural networks. Bagging is probably appropriate for most problems with trees and neural networks, while boosting, where it suits the data, can deliver larger gains. If your labels come from noisy human annotation or delayed outcomes, that noise result should count for more than a leaderboard difference.

Bagged Decision Trees vs a Random Forest

A random forest is bagged trees plus one more source of randomness. At each split, a tree considers only a random subset of the features. In scikit-learn, the default max_features=1.0 in a forest is equivalent to bagged trees, and smaller values add more randomness. Janitza and Hornung describe the same equivalence from the other side: with mtry equal to the number of predictors, a random forest coincides with bagging.

The extra randomness exists to lower ρ in the variance formula above. Bagging alone shrinks the (1 − ρ)σ²/B term, and feature subsampling also attacks the ρσ² term by making the trees less alike, at the cost of somewhat higher bias in each tree. A rule of thumb is 1 ≤ m ≤ √p features per split for classification and 1 ≤ m ≤ p/3 for regression, where p is the number of variables. In Breiman’s 2001 experiments, random forests with random features were always better than plain bagging.

So when does plain bagging still make sense? Mainly when you want to bag something other than a tree, where the forest’s per-split feature sampling has nothing to work with.

The Scikit-Learn Parameters That Matter

Scikit-learn’s bagging estimators expose the mechanism directly: max_samples and max_features set the size of each random subset, and bootstrap and bootstrap_features decide whether rows and features are drawn with replacement, with bootstrap=True the default. Scikit-learn strongly recommends keeping it when fitting with sample_weight. oob_score=True turns on OOB estimation, which is only available when bootstrap=True.

For n_estimators, Breiman used 50 bootstrap replicates for classification and 25 for regression, and said explicitly that these seemed reasonable rather than necessary or sufficient. Opitz and Maclin found much of bagging’s error reduction occurred after ten to fifteen members, for neural networks and similarly for trees. If you plan to rely on OOB estimates, size the ensemble for those estimates rather than for accuracy. Breiman chose 100 trees in his forest experiments so that OOB estimates built on a third of them would be reliable.

When Bagging Fails to Improve a Model

The failure cases are predictable, so check them before adding trees:

  • The base learner is stable. Bagging k-nearest neighbours, a stable procedure, can slightly degrade performance.
  • The model is already near the data’s accuracy limit. No amount of averaging fixes missing signal.
  • The trees are too correlated. The ρσ² floor caps the gain, and a random forest lowers that correlation.
  • A few highly influential examples are bad. Bagging’s deteriorations track the quality of those examples.
  • You needed interpretability. A bagged ensemble gives up the single tree’s simple, readable structure in exchange for accuracy.

The last item matters most in regulated settings, so it gets its own section.

Can a Bagged Tree Ensemble Pass a Model-Risk Review, or Should We Ship a Single Tree?

Lack of interpretation is the main drawback of bagging and of ensembles in general: a combination of decision trees is much harder to interpret than a single tree. Scikit-learn’s documentation notes that a single tree can be read by visualising it, while a gradient-boosted model of hundreds of trees cannot easily be interpreted by inspecting its members. Breiman called a forest impenetrable as far as simple interpretations of its mechanism go.

Supervisory expectations are where that cost becomes concrete. The US model-risk guidance SR 11-7 (Federal Reserve and OCC, 2011) expects documentation detailed enough that someone unfamiliar with a model can understand how it operates, its limitations and its key assumptions. The UK PRA’s SS1/23 (2023) asks firms to tier models by materiality and complexity, and to set the depth of independent review by tier. In US consumer credit, CFPB Circular 2022-03 says creditors may not use complex algorithms if doing so means they cannot give specific and accurate reasons for adverse actions, and that post-hoc explanations must themselves be validated. We are engineers, not counsel. Whether a given model satisfies those texts is for your compliance and legal functions, and the useful thing we can do is make the evidence they need easy to produce.

Here is the part reviewers sometimes miss. SR 11-7 also expects sensitivity analysis, and says unexpectedly large changes in outputs from small changes in inputs can indicate an unstable model. A single deep tree is exactly the kind of learner whose fit moves when the data is perturbed. Choosing the single tree trades an interpretability finding for a stability finding. That trade can be right, but it should be argued, not assumed.

Situation Defensible default Why
Decisions need per-case reasons (credit adverse action, individual eligibility) A single, shallow, pruned tree or another inherently interpretable model Reasons must be specific and accurate, and approximations of a complex model must be validated
High-tier model where reviewers must understand the mechanism Single tree, with sensitivity and stability testing documented Documentation must convey operation and limitations; instability must be checked
Lower-tier model where accuracy matters and outputs are aggregated Bagged trees or a random forest, with OOB and cross-validated error reported Review depth scales with tier; ensembles trade interpretability for accuracy
You want the accuracy gain but must keep one readable tree Grow a single tree on out-of-bag outputs Breiman found OOB outputs do well when the aim is accuracy with interpretability retained

The per-decision trail is the subject of why model accuracy numbers are not a regulator defence. If a bagged model does go forward, we would start by making it reproducible: fixed and recorded seeds, versioned data snapshots, the ensemble size and sampling parameters logged with every run, and OOB alongside stratified cross-validated error in the validation pack. That is reproducibility engineering, the part TechnoLynx would take on rather than the regulatory judgement itself.

FAQ

Can You Give an Example of Sampling Without Replacement?

Drawing a random 60% of rows, each at most once, to train a tree is sampling without replacement. Applied to an ensemble, it is called pasting. Janitza and Hornung used subsamples of ⌊0.632n⌋ rows drawn this way to avoid biases the bootstrap can introduce.

Does Boosting Reduce Bias?

Yes. Boosting and arcing can reduce bias as well as variance, while bagging works mainly on variance. As boosting iterations proceed, bias falls and variance rises.