Back to Classic ML Mind Map
中文·English
📊 Classic MLID: bagging-forest

Bagging & Random Forest

Bagging 与随机森林
🎯Core Definition
Bagging (Bootstrap Aggregating) is a parallel ensemble: for kk base learners, draw nn 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 nn draws with probability (11n)ne10.368\left(1 - \frac{1}{n}\right)^n \to e^{-1} \approx 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\sigma^2 and pairwise correlation ρ\rho, the averaged model has variance Var(fˉ)=ρσ2+1ρkσ2\text{Var}\left(\bar{f}\right) = \rho \sigma^2 + \frac{1 - \rho}{k} \sigma^2 — the first term survives as kk \to \infty, so the real lever of bagging is reducing ρ\rho, not just increasing kk. Random Forest adds feature randomness: at each split, sample mdm \approx \sqrt{d} features out of dd (regression: ~d/3d/3) and pick the best split among them — the double randomness (samples + features) lowers ρ\rho substantially. From the bias-variance decomposition Err=bias2+variance+σϵ2\text{Err} = \text{bias}^2 + \text{variance} + \sigma_\epsilon^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 mm 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\rho \to 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 mm → small ρ\rho) drops variance from the σ2\sigma^2 level to the ρσ2\rho \sigma^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 (11n)ne10.368(1 - \frac{1}{n})^n \to e^{-1} \approx 0.368; how is OOB error computed and why does it need no separate validation set?
2
Variance decomposition: Var(fˉ)=ρσ2+1ρkσ2\text{Var}(\bar{f}) = \rho \sigma^2 + \frac{1-\rho}{k} \sigma^2 — why does bagging reduce variance but not bias? Why is variance not zero as kk \to \infty?
3
RF double randomness: bootstrap samples + random feature subsets (m=dm = \sqrt{d} classification / d/3d/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?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "Bagging & Random Forest"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardTree PruningNext CardAdaBoost Derivation

🔗 More Classic ML Knowledge Cards

Baum-Welch (HMM EM)GBDT Negative GradientConfusion MatrixLinear-Chain CRF