M2-012M2: Classical Machine LearningRegularization (L1 / L2)Easy
⚡Flashcard Drill➔Mastery:
Explain Hyperparameter Selection for Regularization Strength Lambda and Diagnostic Extremes
📐 Mathematical Definition
⚡ One-Sentence Core Answer
The regularization coefficient balances empirical fit against model complexity, selected via cross-validation to minimize validation loss; excessively large causes underfitting (high bias), while tiny causes overfitting (high variance).
📌 Key Takeaways
- •Underfitting (): Model is crushed toward zero (); training loss is high, validation loss is high (High Bias).
- •Overfitting (): Model reduces to unregularized OLS/MLE; training loss is near zero, validation loss blows up (High Variance).
- •Optimal : Minimum of the U-shaped cross-validation error curve (or the 'One-Standard-Error Rule' for parsimony).
📐 Mathematical Derivations
Cross-validation selection protocol: Define a logarithmic grid of candidate values . For each , evaluate -fold cross-validation error: . Compute the standard error of the CV estimate: . The One-Standard-Error Rule (Hastie et al.) selects the simplest model (largest ) whose error is within 1 SE of the minimum: , 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 in the same computational complexity as a single OLS inversion (), allowing exact evaluation of all without grid search.
⚠️ Common Interview Pitfalls
- ✕Selecting 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. instead of ).
🎯 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.
📚
Associated Knowledge Base Guides & Mindmaps
Explore the comprehensive technical article, exam cards, and global architecture tree.
中文速览与面试要点
正则化系数 λ 如何选择?过大过小分别会怎样。
用交叉验证选择;λ 过大 → 欠拟合(高偏差),过小 → 过拟合(高方差)。
核心要点
- λ 的作用是控制偏差-方差权衡:λ→0 时退化为无正则的 MLE(低偏差高方差,过拟合);λ→∞ 时所有系数收缩到 0(高偏差低方差,欠拟合)。选择方法是 交叉验证 :在对数尺度上网格搜索(如 λ∈10⁻⁴,…,10⁴,通常 100 个点),对每个 λ 计算 K 折 CV 误差,取最小者。选择对数网格的原因:λ 的效应是乘性的(λ 与 2λ 的差异类似 100λ 与 200λ),且最优 λ 的量级跨越多个数量级。
- 三个实践要点:① 1SE 规则 ——不取 CV 误差最小的 λ,而取'误差在最小值 1 个标准误内的最大 λ',即更简单的模型。理由是 CV 误差曲线在最小值附近很平坦,而更大 λ 带来更好的泛化稳定性(Occam 剃刀);这在特征选择场景尤其重要(减少假阳性特征)。② λ 与数据的尺度相关 ——若特征未标准化,λ 的最优值会随量纲变化;因此标准化后再调 λ。③ 嵌套 CV 的必要性 ——若用同一份数据既选 λ 又报告性能,会得到 乐观偏差 的估计(因为 λ 被选为对这份数据最优);正确做法是外层 CV 评估性能、内层 CV 选 λ。此外,正则化路径(λ 从大到小)的计算可用 热启动 (warm start)加速——坐标下降从上一个 λ 的解出发,使整条路径的计算成本接近单个 λ。
- 1SE 规则倾向更简单的模型
- 用对数网格搜索
常见陷阱
- 未标准化特征就调 λ
- 用同一份 CV 结果既选 λ 又报告性能(乐观偏差)