Bagging (Bootstrap Aggregating) is a parallel ensemble: for k base learners, draw n samples with replacement from the training set (bootstrap) and train each learner on its own bag; predict by voting (classification) or averaging (regression). Key probability: a given sample is never drawn in n draws with probability (1−n1)n→e−1≈0.368, so each bag contains only ~63.2% of the original samples on average and the remaining ~36.8% (≈ 1/3) are Out-of-Bag (OOB) samples unseen by that learner — evaluating on them gives the OOB error, an unbiased estimate without a separate validation set. Variance analysis: for base learners with variance σ2 and pairwise correlation ρ, the averaged model has variance Var(fˉ)=ρσ2+k1−ρσ2 — the first term survives as k→∞, so the real lever of bagging is reducing ρ, not just increasing k. Random Forest adds feature randomness: at each split, sample m≈d features out of d (regression: ~d/3) and pick the best split among them — the double randomness (samples + features) lowers ρ substantially. From the bias-variance decomposition Err=bias2+variance+σϵ2: averaging does not change bias, only variance, so bagging suits strong low-bias high-variance base learners (deep, unpruned trees).
💡Use Cases
why random forests beat single deep trees, what OOB error is, how m is chosen, and why random forests parallelize — all are frequent interview topics; RF is also a strong baseline for tabular data, natively providing feature importance (mean split gain).
⚡Key Problems Solved
single deep trees have large variance and overfit — bootstrap resampling creates data perturbation so base learners differ (without replacement, the bags would be too similar, ρ→1, and averaging would barely reduce variance); in pure bagging strong features dominate every split so trees stay highly correlated, and feature-subset randomization (small m → small ρ) drops variance from the σ2 level to the ρσ2 level — the key reason RF beats plain bagging; OOB makes evaluation isomorphic to training at zero extra data cost, and every tree trains fully in parallel.
🎯5 High-Frequency Exam Points
1
Bootstrap derivation: probability a sample is never drawn is (1−n1)n→e−1≈0.368; how is OOB error computed and why does it need no separate validation set?
2
Variance decomposition: Var(fˉ)=ρσ2+k1−ρσ2 — why does bagging reduce variance but not bias? Why is variance not zero as k→∞?
3
RF double randomness: bootstrap samples + random feature subsets (m=d classification / d/3 regression); why is feature randomness the key ingredient?
4
Why must bagging base learners be strong (deep, unpruned)? What happens if they are shallow?
5
OOB error vs K-Fold CV error: pros and cons; how does RF use OOB to compute feature importance?