M2-102M2: Classical Machine LearningBias-Variance Tradeoff & Model SelectionMedium
⚡Flashcard Drill➔Mastery:

How Model Ensembling Impacts Bias and Variance

📐 Mathematical Definition
Var(fˉ)=ρσ2+1−ρBσ2,Bias(fˉ)≈Bias(f)\mathrm{Var}(\bar f)=\rho\sigma^2+\frac{1-\rho}{B}\sigma^2,\qquad \mathrm{Bias}(\bar f)\approx\mathrm{Bias}(f)
⚡ One-Sentence Core Answer
Bagging reduces variance through parallel averaging; Boosting reduces bias through sequential residual fitting; Stacking optimizes combinations of diverse base hypotheses.

📌 Key Takeaways

  • •
    Bagging: Var(fˉ)=ρσ2+1−ρBσ2\text{Var}(\bar{f}) = \rho \sigma^2 + \frac{1-\rho}{B} \sigma^2; reduces variance, leaves bias unchanged
  • •
    Boosting: constructs additive expansion Fm(x)=Fm−1(x)+γmhm(x)F_m(x) = F_{m-1}(x) + \gamma_m h_m(x) targeting residuals; shrinks bias
  • •
    Stacking: trains a meta-learner on out-of-fold base predictions, combining diverse inductive biases

📐 Mathematical Derivations

Mathematical Decomposition:
① Bagging Variance Reduction: Let BB base learners each have variance σ2\sigma^2 and pairwise correlation ρ\rho. The variance of the ensemble mean fˉ=1B∑i=1Bfi\bar{f} = \frac{1}{B} \sum_{i=1}^B f_i is: Var(fˉ)=ρσ2+1−ρBσ2\text{Var}(\bar{f}) = \rho \sigma^2 + \frac{1 - \rho}{B} \sigma^2. As B→∞B \to \infty, the second term vanishes, leaving the irreducible floor ρσ2\rho \sigma^2. Decorrelating base learners (reducing ρ\rho via feature subsampling in Random Forest) directly minimizes this floor.
② Boosting Bias Reduction: Each sequential learner hmh_m fits the pseudo-residuals rim=−[∂L(yi,F(xi))∂F(xi)]F=Fm−1r_{im} = -\left[\frac{\partial \mathcal{L}(y_i, F(x_i))}{\partial F(x_i)}\right]_{F=F_{m-1}}, performing functional gradient descent that systematically contracts approximation bias at rate O(e−cm)O(e^{-c m}).

🏭 Production Trade-offs

Base learner pairing: Pair Bagging with high-variance, low-bias learners (deep, unpruned decision trees). Pair Boosting with low-variance, weak learners (shallow trees, decision stumps). In Stacking, ensure diverse algorithmic families (e.g., GBDT + Ridge + Neural Net) rather than homogenous models.
⚠️ Common Interview Pitfalls
  • ✕
    Using Bagging on high-bias linear models, expecting variance reduction to improve underfitting
  • ✕
    Ensembling identical or highly correlated models (ρ≈1\rho \approx 1), which yields near-zero variance reduction
🎯 Interviewer Follow-up Inquiries
  • ?
    Why does Random Forest randomly select a subset of features at each split, and how does that affect ρ\rho in the variance formula?
  • ?
    Why can boosting overfit noisy data if iterations continue without early stopping?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

Explore the comprehensive technical article, exam cards, and global architecture tree.

← PreviousM2-101: Learning Curves vs Validation Curves: Formulations and Diagnostic Workflows📋Back to BankNext →M2-103: When Does Adding More Data Fail to Improve Model Performance?
中文速览与面试要点

解释模型集成如何影响偏差与方差

平均降方差(Bagging);串行纠错降偏差(Boosting);Stacking 可同时降两者但需防泄漏。

核心要点

  • 三种集成的偏差-方差效果:① Bagging(并行平均) ——平均 B 个近似独立的模型,方差降为 ρσ²+(1−ρ)σ²/B(ρ 为模型间相关系数),但 偏差近似不变 (因为各模型同偏,平均不能消除系统性偏差)。故 Bagging 适合 高方差低偏差 的基学习器(深树)。② Boosting(串行纠错) ——每轮拟合前一轮的残差/负梯度,逐步 降低偏差 ;但由于模型变得复杂且依赖训练数据, 方差可能上升 (这也是 Boosting 需早停/正则的原因)。适合 低方差高偏差 的基学习器(浅树/决策桩)。③ Stacking(元学习器组合) ——理论上可同时利用不同模型的偏差与方差特性(元学习器学习'何时信任谁'),故可能同时降两者;但需用 CV 生成元特征防泄漏,且元学习器本身可能过拟合。 集成何时可能变差 :若基学习器 性能差异极大 (如包含一个很差的模型),简单平均会被拖累;若基学习器 高度相关 (ρ→1),Bagging 的降方差收益消失(方差下界 ρσ²);若基学习器 都是高偏差 (如全是线性模型),平均不能降偏差。
  • 实践要点:① 基学习器的选择原则 ——Bagging/RF 用 高方差 模型(深树、未剪枝);Boosting 用 低方差 模型(浅树、决策桩);Stacking 追求 多样性 (不同归纳偏置:树 + 线性 + KNN + 神经网络)。② 相关性的核心作用 ——Bagging 的效果由 ρ 决定:特征子采样(RF)、不同初始化、不同数据子集都能降低 ρ;若基学习器相关性高,应主动引入随机性。③ B 的收益递减 ——由于 ρσ² 项不随 B 消失,B 增大收益递减;实践中 B=100–500 通常足够。④ 集成与正则化的关系 ——集成是一种'结构性正则',与 L1/L2/dropout 可叠加;但过度集成会欠拟合(尤其 Boosting 轮数过多)。⑤ Stacking 的泄漏风险 ——必须用 K 折 CV 生成元特征(详见 Stacking 题);且元学习器应简单(线性/浅树)。⑥ 实践建议 ——先用单一强模型建立基线,再试简单平均(若基模型性能相近常与 Stacking 相当且更简单),最后考虑 Stacking;同时报告 集成的方差 (多种子)以确认提升不是噪声。
  • Bagging 不改变偏差(近似),只降方差
  • Boosting 主要降偏差,可能升方差

常见陷阱

  • 用 Bagging 处理高偏差问题(应用 Boosting)
  • 基学习器高度相关时期待 Bagging 大幅降方差