Skip to content
AI360XpertBeta
Core ML

Visual explainer

Bagging vs Boosting

Bagging averages separately fitted predictions; boosting adds corrections to the current ensemble. Follow both through four targets and their limits.

One constant prediction misses both levels of the target.
One constant prediction misses both levels of the target.

Bagging combines separately trained models. Boosting trains a correction conditional on the ensemble already built. Neither guarantees a better model. Our synthetic regression fixture has four rows: A at (x,y)=(1,2)(x,y)=(1,2), B at (2,2)(2,2), C at (3,6)(3,6) and D at (4,6)(4,6). Rings are targets; vertical position is the response in arbitrary units. The constant mean F0=4F_0=4 misses every target by two, giving mean squared error (MSE) 4.

Resample the Rows

Bootstrap draws repeat rows and change fitted means.
Bootstrap draws repeat rows and change fitted means.

Each column contains four draws with replacement, so a row can appear repeatedly or be absent. These are bags, not disjoint validation folds. For a deliberately simple bagging example, each member is a depth-zero regression tree: one leaf predicting its bag's mean. AAAD predicts (2+2+2+6)/4=3(2+2+2+6)/4=3; ACCC predicts 5; ABCD predicts 4. The fits have no dependency on one another and can run in parallel. The original data are shared, so independent draws do not imply independent prediction errors.

Fit What Remains

Squared-loss boosting fits signed residuals of the current ensemble.
Squared-loss boosting fits signed residuals of the current ensemble.

For squared loss, the residual targets are y−F0=(−2,−2,2,2)y-F_0=(-2,-2,2,2). The bars extend below or above zero according to sign. A regression stump split at x=2.5x=2.5 fits the left residuals with −2-2 and the right residuals with +2+2. This correction tree follows the current ensemble; its target depends on that ensemble. Other losses use different gradient targets, and AdaBoost uses sample reweighting rather than this literal residual procedure.

Average or Add?

Bagging averages complete predictions while boosting adds corrections.
Bagging averages complete predictions while boosting adds corrections.

The top number line shows the three bagged predictions 3, 4 and 5. Their average is the diamond at 4. The bottom line follows a right-side input through one boosting update: 4+0.5(2)=54+0.5(2)=5. Both lines use the same horizontal response scale. One operation averages complete predictions; the other adds a scaled correction. In classification, aggregation depends on the algorithm: votes, averaged probabilities or a transformed additive score are different objects.

The Variance Floor

Correlated members leave a variance floor after averaging.
Correlated members leave a variance floor after averaging.

This separate theoretical illustration assumes each member has prediction variance 1 across repeated training sets, with common pairwise correlation ρ=0.4\rho=0.4. Then Var⁡(fˉ)=ρ+(1−ρ)/M\operatorname{Var}(\bar f)=\rho+(1-\rho)/M. One member gives 1; five give 0.52; infinitely many approach 0.4. Bar lengths share one zero and scale. These are consequences of stated covariance assumptions, not measured results for our three bags. Adding members cannot average away their shared error component.

Take a Partial Step

Shrinkage moves each boosted plateau partway toward its target.
Shrinkage moves each boosted plateau partway toward its target.

We return to the four-row fixture and choose learning rate η=0.5\eta=0.5. The dashed horizontal line is the old prediction 4. Adding half the stump gives (3,3,5,5)(3,3,5,5), so every squared residual becomes 1 and MSE falls to 1. The arrows show exactly one response unit of movement. A smaller learning rate changes the step and usually needs more stages; select it jointly with tree size and stage count using held-out evidence. Noise alone does not settle the bagging-versus-boosting decision.

Evaluate an Excluded Row

Out-of-bag evaluation uses only members that excluded the row.
Out-of-bag evaluation uses only members that excluded the row.

AAAD never used B or C during fitting. Its prediction 3 can therefore be compared with B's target 2, shown in the circle: squared error (3−2)2=1(3-2)^2=1. An out-of-bag prediction for a row aggregates only members whose bags excluded it. In this tiny three-member ensemble, some rows have no such members; an OOB score is not automatically available or reliable for every row. This evaluates bagged models without pretending their training predictions are unseen predictions.

Predict a Fresh Input

Inference averages bag members but sums both boosting stages.
Inference averages bag members but sums both boosting stages.

At x=3.5x=3.5, the three constant bag members still average to 4. For boosting, after the first update the residuals are (−1,−1,1,1)(-1,-1,1,1). A second stump uses the same split and contributes half those values. The right-side prediction becomes 4+1+0.5=5.54+1+0.5=5.5; the left becomes 2.5, and training MSE becomes 0.25. The two arrow lengths are in a 2:1 ratio. Prediction uses the base constant and both corrections; the final correction alone is not the prediction. No unseen target was supplied for this query, so this scene establishes inference, not test accuracy.

Noise Still Enters Bags

A corrupted row can enter most bootstrap samples.
A corrupted row can enter most bootstrap samples.

Suppose D's label is corrupted, marked with an amber cross. Four independent replacement draws miss D with probability (3/4)4=81/256(3/4)^4=81/256. They include it with probability 175/256≈0.684175/256\approx0.684, represented by the longer bar segment. These are probabilities over all 256 equally likely ordered draws, not observed frequencies. Bagging is not immune to contaminated labels. Squared-loss boosting can also chase large corrupt residuals; loss choice, regularization and validation matter for both.

Where It Breaks

Both constant-leaf ensembles stay flat beyond the training range.
Both constant-leaf ensembles stay flat beyond the training range.

The scale changes explicitly here to include x=6x=6 and response 8. Training ends at x=4x=4, marked by the dashed vertical edge. The white segments show the observed target levels; the rising dashed continuation is a hypothetical unseen target reaching 8 at x=6x=6. Our bagged model stays at 4; the two-stage boosted model stays at 5.5. Both miss that hypothetical target, shown by crosses. Finite sums or averages of constant-leaf trees do not continue a rising slope beyond their last split. A stronger training fit supplies no evidence about this unseen continuation.

The Quick Version

  • Bagging averages models fitted on resampled data.
  • Boosting adds corrections conditioned on the current ensemble.
  • Squared-loss residuals can be positive or negative.
  • Shrinkage controls each correction's contribution.
  • Correlated errors leave an averaging floor.
  • Out-of-bag predictions exclude the evaluated row from fitting.
  • Neither method guarantees robustness or extrapolation.

Mechanism reference: scikit-learn ensemble guide. All fixtures and geometry above are illustrative calculations, not benchmark claims.