Ridge & Lasso
Regularization
Learn how penalty terms tame overfitting by shrinking coefficients: the \(\ell_2\) circle of Ridge and the \(\ell_1\) diamond of Lasso.
The Overfitting Problem
In ordinary least squares (OLS), we minimize the residual sum of squares: \(\text{RSS} = \sum_{i=1}^{n}(y_i - \hat{y}_i)^2\). With many predictors, OLS fits the training data perfectly but generalizes poorly.
Regularization adds a penalty to the loss function, forcing coefficients toward zero. This trades a small increase in bias for a large decrease in variance.
What Is Regularization?
Two Norms, Two Methods
Constraint region is a circle (or hypersphere). Shrinks coefficients smoothly toward zero but never exactly to zero.
Constraint region is a diamond. Can shrink coefficients exactly to zero, performing automatic feature selection.
Ridge Regression: The \(\ell_2\) Penalty
Ridge has a closed-form solution: $$\hat{\boldsymbol{\beta}}^{\text{ridge}} = \left(\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I}\right)^{-1}\mathbf{X}^T\mathbf{y}$$
Lasso Regression: The \(\ell_1\) Penalty
Unlike Ridge, Lasso has no closed-form solution because the \(|\beta_j|\) terms are not differentiable at zero. It requires iterative algorithms like coordinate descent.
Geometric Intuition: Why Lasso Zeros Out
The OLS solution sits at the center of elliptical contours of constant RSS. Regularization constrains \(\boldsymbol{\beta}\) to lie within a region. The solution is where the contours first touch the constraint region.
Ridge vs. Lasso: Key Distinction
| Ridge (\(\ell_2\)) | Lasso (\(\ell_1\)) | |
|---|---|---|
| Penalty | \(\lambda \sum \beta_j^2\) | \(\lambda \sum |\beta_j|\) |
| Constraint Shape | Circle / sphere | Diamond / cross-polytope |
| Sparsity | No: shrinks, never zeros | Yes: exact zeros |
| Feature Selection | No | Yes |
| Closed Form | Yes | No (iterative) |
| Correlated Features | Handles well | Unstable selection |
| Best When | Many small effects | Few large effects |
Tuning \(\lambda\): The Bias-Variance Trade-off
Coefficient Paths as \(\lambda\) Grows
Elastic Net: Best of Both
Elastic Net overcomes Lasso's instability with correlated predictors by adding an \(\ell_2\) component that encourages grouping: correlated variables enter or leave the model together.
How to Apply Regularization
Example 1: Ridge with Two Predictors
Suppose we have standardized predictors \(x_1, x_2\) and the OLS estimates are \(\hat{\beta}_1^{\text{OLS}} = 3.2\) and \(\hat{\beta}_2^{\text{OLS}} = -1.8\). We apply Ridge with \(\lambda = 2\).
Example 2: Lasso Soft Thresholding
For a single predictor (orthonormal design), the Lasso solution is the soft-thresholding operator:
Using \(\hat{\beta}_1^{\text{OLS}} = 3.2\), \(\hat{\beta}_2^{\text{OLS}} = -1.8\), and \(\lambda = 4\):
= \(+1 \cdot 1.2 = 1.2\)
= \(-1 \cdot 0 = 0\)
Example 3: Comparing Ridge vs. Lasso
A dataset has \(p = 5\) predictors with OLS coefficients \(\hat{\boldsymbol{\beta}}^{\text{OLS}} = (4.1,\; 0.3,\; -2.5,\; 0.1,\; 1.8)\). We set \(\lambda = 1\) for both methods (standardized design).
| Predictor | OLS | Ridge | Lasso |
|---|---|---|---|
| \(x_1\) | 4.1 | 2.05 | 3.6 |
| \(x_2\) | 0.3 | 0.15 | 0 |
| \(x_3\) | -2.5 | -1.25 | -2.0 |
| \(x_4\) | 0.1 | 0.05 | 0 |
| \(x_5\) | 1.8 | 0.90 | 1.3 |
Common Mistakes
Question 1 of 5
Which regularization method can set coefficients exactly to zero, thereby performing automatic feature selection?
Question 2 of 5
The Ridge regression closed-form solution is \(\hat{\boldsymbol{\beta}} = (\mathbf{X}^T\mathbf{X} + \lambda\mathbf{I})^{-1}\mathbf{X}^T\mathbf{y}\). What happens as \(\lambda \to \infty\)?
Question 3 of 5
Given OLS estimate \(\hat{\beta}^{\text{OLS}} = 2.5\) and \(\lambda = 5\), what is the Lasso estimate using the soft-thresholding formula for an orthonormal design?
Question 4 of 5
Why must predictors be standardized before applying Ridge or Lasso regression?
Question 5 of 5
Elastic Net combines \(\ell_1\) and \(\ell_2\) penalties. When is it most advantageous over using pure Lasso?