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

Compare the Geometric and Functional Differences Between L1, L2, and ElasticNet Regularization

🎯 Active Recall Self-Check (Draft First, Verify After)
Login-free practice tracker: recall core answer, audit pitfalls, and log review status.
Step 1 · Draft your concise answer & assumptions
Step 2 · Check Pitfalls & Follow-up Inquiries
Next: M2-012 →
📐 Mathematical Definition
L1:λ∥w∥1,L2:λ∥w∥22,EN:λ1∥w∥1+λ2∥w∥22L1:\lambda\|w\|_1,\quad L2:\lambda\|w\|_2^2,\quad EN:\lambda_1\|w\|_1+\lambda_2\|w\|_2^2
⚡ One-Sentence Core Answer
L1 (Lasso) promotes sparsity by shrinking coefficients to exact zero on diamond corners; L2 (Ridge) shrinks coefficients smoothly without sparsity; ElasticNet combines both, grouping correlated features while maintaining sparsity.

📌 Key Takeaways

  • •
    Constraint Ball Geometry: L1 ball ∥w∥1≤C\|w\|_1 \le C has sharp vertices on axes where wi=0w_i=0; L2 ball ∥w∥22≤C\|w\|_2^2 \le C is smooth and spherical.
  • •
    L1 (Lasso): Automatic feature selection, sparse models; under collinearity, arbitrarily selects one feature from a correlated cluster.
  • •
    L2 (Ridge): Solves multicollinearity, distributes weights evenly among correlated features; no sparsity.
  • •
    ElasticNet: L=Loss+λ1∥w∥1+λ22∥w∥22L = \text{Loss} + \lambda_1 \|w\|_1 + \frac{\lambda_2}{2}\|w\|_2^2; strictly convex, retains group selection property.

📐 Mathematical Derivations

Analysis of ElasticNet grouping effect: Let features xix_i and xjx_j be highly correlated (r=xiTxjr = x_i^T x_j). For strictly convex ElasticNet with λ2>0\lambda_2 > 0, Zou & Hastie (2005) proved that the difference in estimated coefficients satisfies: ∥β^i−β^j∥≤∥y∥2λ22(1−r)\|\hat{\beta}_i - \hat{\beta}_j\| \le \frac{\|y\|_2}{\lambda_2} \sqrt{2(1 - r)}. As correlation r→1r \to 1, ∥β^i−β^j∥→0\|\hat{\beta}_i - \hat{\beta}_j\| \to 0, forcing correlated features to receive nearly identical coefficients. In pure Lasso (λ2=0\lambda_2 = 0), this bound does not exist, causing one coefficient to take the entire weight while the other is set to zero arbitrarily.

🏭 Production Trade-offs

When to choose which: (1) L1: High-dimensional sparse feature regimes (e.g. 1 million text n-grams or gene expressions) where 99% of features are noise. (2) L2: Dense numerical signals where all features contribute small predictive value and collinearity must be controlled. (3) ElasticNet: High-dimensional data with multicollinear feature clusters (p≫np \gg n), achieving both sparsity and group stability.
⚠️ Common Interview Pitfalls
  • ✕
    Using pure Lasso when p>np > n (Lasso can select at most nn non-zero features before saturating; ElasticNet can select all pp features).
  • ✕
    Forgetting to scale/normalize features prior to applying L1/L2 penalties.
🎯 Interviewer Follow-up Inquiries
  • ?
    Why can Lasso select at most nn features when p>np > n, and how does ElasticNet overcome this limit?
  • ?
    How does the L1/2 norm compare to L1, and why is it non-convex?
⚡
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

← PreviousM2-010: Explain Complete Separation (Hauck-Donner Effect) in Logistic Regression and Standard Industrial Solutions📋 Back to BankNext →M2-012: Explain Hyperparameter Selection for Regularization Strength Lambda and Diagnostic Extremes
中文速览与面试要点

比较 L1、L2 与 ElasticNet 正则化的几何与效果差异。

L1 稀疏(特征选择),L2 收缩(抗共线),ElasticNet 兼顾两者。

核心要点

  • 几何视角最直观:约束形式 min‖y−Xw‖² s.t. ‖w‖₁≤t 的可行域是 菱形 (顶点在坐标轴上),L2 约束的可行域是 圆 (无顶点)。损失等高线(椭圆)与可行域首次相切处即最优解;菱形的尖角使切点极可能落在坐标轴上 → 某些 wⱼ=0(稀疏)。解析视角:L1 的最优性条件含次梯度 ∂|wⱼ|=[−1,1](当 wⱼ=0),这给出 软阈值 wⱼ=sign(zⱼ)max(|zⱼ|−λ,0),即 |zⱼ|≤λ 的系数被精确置零;而 L2 的导数 2λwⱼ 在 0 处为 0,无法把系数推到零。
  • 实践选择依据:① L1(LASSO) ——需要特征选择、高维稀疏(文本、基因)、要求可解释性;缺点是相关特征组中 只随机保留一个 (选择不稳定)、解路径不连续、p>n 时最多选出 n 个非零系数。② L2(Ridge) ——特征都相关且有贡献、共线性严重、p>n 场景;缺点是 不产生稀疏解 ,模型包含全部特征。③ ElasticNet ——两者结合,既稀疏又在相关特征组上稳定('分组效应':相关特征倾向于同进同出);代价是需调两个超参(λ₁、λ₂),可用 CV 在二维网格搜索。④ 算法差异 ——L1 不可微,用坐标下降(最常用,因每步有解析解)、近端梯度(ISTA/FISTA)、或 ADMM;L2 有闭式解或可直接用梯度法。⑤ 实践中 :若只关心预测精度,L2 通常足够;若需特征选择,L1 或 ElasticNet;若特征间相关性强且需稀疏,优先 ElasticNet。
  • L1 在 0 处不可导 → 坐标下降/近端法
  • L2 有闭式解且可微
  • EN 在强相关特征组上更稳定

常见陷阱

  • 认为 L1 在相关特征上稳定(实际随机选一个)
  • 以为 L2 也能产生精确零(只收缩不置零)