Boosting vs bagging
What it is
Bagging fits B independent models on perturbed copies of the data and averages them. Boosting fits models one at a time, each on a version of the problem reweighted or re-targeted by the errors of the current ensemble, and *adds* them up with a small multiplier.
Why it matters
The two reduce different error components, so they want opposite base learners. Bagging wants deep unpruned trees, because it removes variance and needs low bias to start from. Boosting wants stumps or depth-3 trees, because it removes bias and would amplify variance if each member had much.
In the real world: Boosting builds models one after another, each fixing the last one's mistakes: why it often wins on fraud and pricing data.
Visual example
Bagging vs boostingThe same base learner, used two ways. Read the depth wanted and n_estimators risk rows together.
Why the depths differ
bagging: bias^2 survives averaging, so start with a near-zero-bias (deep) tree
boosting: each round reduces bias, so a low-variance (shallow) tree is the right unit
a deep tree inside a GBM zeroes the residuals in one round — nothing left to boost
a stump inside a bagging ensemble has no variance to average away
Why this matters
Almost every gradient-boosting mistake is a random-forest reflex applied in the wrong place: growing deep, adding estimators freely, and not watching a validation curve.
Common misconception
Wrong idea: boosting is bagging with the trees added instead of averaged.
Correct idea: boosting changes what each tree is fitted to. Every tree after the first is trained on a target the earlier trees created.
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from sklearn.model_selection import cross_val_score
# deep trees, averaged in parallel
RandomForestClassifier(n_estimators=300, max_depth=None, random_state=0)
# shallow trees, summed in sequence
GradientBoostingClassifier(n_estimators=300, max_depth=3, learning_rate=0.1,
random_state=0)
# both ~0.96-0.98 here; their failure modes are completely differentCarrying forest habits over. max_depth=None in a GBM is not 'letting it learn' — each tree then fits the residuals almost exactly, the next tree has nothing left to correct, and the ensemble overfits within a handful of rounds. Depth 3 to 6 is the working range, and n_jobs cannot parallelise across rounds because round m+1 needs round m's output.