M2-012M2: Classical Machine LearningRegularization (L1 / L2)Easy
⚡Flashcard Drill➔Mastery:

Explain Hyperparameter Selection for Regularization Strength Lambda and Diagnostic Extremes

📐 Mathematical Definition
λ∗=arg⁡min⁡λ CV error(λ)\lambda^*=\arg\min_\lambda\ \text{CV error}(\lambda)
⚡ One-Sentence Core Answer
The regularization coefficient λ\lambda balances empirical fit against model complexity, selected via cross-validation to minimize validation loss; excessively large λ\lambda causes underfitting (high bias), while tiny λ\lambda causes overfitting (high variance).

📌 Key Takeaways

  • •
    Underfitting (λ→∞\lambda \to \infty): Model is crushed toward zero (w→0w \to 0); training loss is high, validation loss is high (High Bias).
  • •
    Overfitting (λ→0\lambda \to 0): Model reduces to unregularized OLS/MLE; training loss is near zero, validation loss blows up (High Variance).
  • •
    Optimal λ∗\lambda^*: Minimum of the U-shaped cross-validation error curve (or the 'One-Standard-Error Rule' λ1SE\lambda_{\text{1SE}} for parsimony).

📐 Mathematical Derivations

Cross-validation selection protocol: Define a logarithmic grid of candidate values Λ={10−4,10−3,…,103}\Lambda = \{10^{-4}, 10^{-3}, \dots, 10^3\}. For each λ∈Λ\lambda \in \Lambda, evaluate KK-fold cross-validation error: CV(λ)=1K∑k=1KLval,k(w^(−k)(λ))\text{CV}(\lambda) = \frac{1}{K}\sum_{k=1}^K \mathcal{L}_{\text{val}, k}(\hat{w}_{(-k)}(\lambda)). Compute the standard error of the CV estimate: SE(λ)=std(CV1,…,CVK)K\text{SE}(\lambda) = \frac{\text{std}(\text{CV}_1, \dots, \text{CV}_K)}{\sqrt{K}}. The One-Standard-Error Rule (Hastie et al.) selects the simplest model (largest λ\lambda) whose error is within 1 SE of the minimum: λ1SE=max⁡{λ:CV(λ)≤CV(λ∗)+SE(λ∗)}\lambda_{\text{1SE}} = \max \{\lambda : \text{CV}(\lambda) \le \text{CV}(\lambda^*) + \text{SE}(\lambda^*)\}, favoring sparser, more robust models over marginal metric noise.

🏭 Production Trade-offs

Regularization path efficiency: For linear models with L1 regularization, the LARS (Least Angle Regression) algorithm computes the entire continuous regularization path for all λ∈[0,∞)\lambda \in [0, \infty) in the same computational complexity as a single OLS inversion (O(Nd2)O(N d^2)), allowing exact evaluation of all λ\lambda without grid search.
⚠️ Common Interview Pitfalls
  • ✕
    Selecting λ\lambda by evaluating on the test set instead of cross-validation (causes data leakage and overly optimistic performance estimates).
  • ✕
    Using a linear search grid instead of a logarithmic scale (e.g. [0.1,0.2,0.3][0.1, 0.2, 0.3] instead of [10−4,10−3,10−2,… ][10^{-4}, 10^{-3}, 10^{-2}, \dots]).
🎯 Interviewer Follow-up Inquiries
  • ?
    What is the 'One-Standard-Error Rule' and why does it guard against empirical overfitting during cross-validation?
  • ?
    How does the LARS algorithm construct the full piecewise linear regularization path for Lasso?
⚡
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-011: Compare the Geometric and Functional Differences Between L1, L2, and ElasticNet Regularization📋Back to BankNext →M2-013: Explain Why Dropout Acts as a Regularizer Through Ensemble and Feature Noise Perspectives
中文速览与面试要点

正则化系数 λ 如何选择?过大过小分别会怎样。

用交叉验证选择;λ 过大 → 欠拟合(高偏差),过小 → 过拟合(高方差)。

核心要点

  • λ 的作用是控制偏差-方差权衡:λ→0 时退化为无正则的 MLE(低偏差高方差,过拟合);λ→∞ 时所有系数收缩到 0(高偏差低方差,欠拟合)。选择方法是 交叉验证 :在对数尺度上网格搜索(如 λ∈10⁻⁴,…,10⁴,通常 100 个点),对每个 λ 计算 K 折 CV 误差,取最小者。选择对数网格的原因:λ 的效应是乘性的(λ 与 2λ 的差异类似 100λ 与 200λ),且最优 λ 的量级跨越多个数量级。
  • 三个实践要点:① 1SE 规则 ——不取 CV 误差最小的 λ,而取'误差在最小值 1 个标准误内的最大 λ',即更简单的模型。理由是 CV 误差曲线在最小值附近很平坦,而更大 λ 带来更好的泛化稳定性(Occam 剃刀);这在特征选择场景尤其重要(减少假阳性特征)。② λ 与数据的尺度相关 ——若特征未标准化,λ 的最优值会随量纲变化;因此标准化后再调 λ。③ 嵌套 CV 的必要性 ——若用同一份数据既选 λ 又报告性能,会得到 乐观偏差 的估计(因为 λ 被选为对这份数据最优);正确做法是外层 CV 评估性能、内层 CV 选 λ。此外,正则化路径(λ 从大到小)的计算可用 热启动 (warm start)加速——坐标下降从上一个 λ 的解出发,使整条路径的计算成本接近单个 λ。
  • 1SE 规则倾向更简单的模型
  • 用对数网格搜索

常见陷阱

  • 未标准化特征就调 λ
  • 用同一份 CV 结果既选 λ 又报告性能(乐观偏差)