Ridge & Lasso Regression
Complete derivation of penalized least squares: the ridge closed-form solution, spectral shrinkage, Lasso sparsity via subgradient conditions, coordinate descent, solution path behavior, and the geometry of constrained optimization.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- Ridge Regression: Derivation
- Spectral Analysis of Ridge
- Ridge Bias-Variance Tradeoff
- Lasso Regression: Formulation
- Subgradient Optimality and Sparsity
- Coordinate Descent for Lasso
- The Regularization Path
- Geometric Interpretation
- Model Selection: Choosing Lambda
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Derive the ridge regression estimator and its relationship to SVD.
- Quantify how ridge shrinks eigencomponents differentially.
- Derive the subgradient optimality condition for Lasso.
- Implement coordinate descent conceptually.
- Explain why L1 produces exactly zero coefficients but L2 does not.
- Describe the full regularization path as varies.
Notation
- — design matrix (rows = samples)
- — response vector
- — regularized coefficient estimate
- — singular values of
- — subdifferential of L1 norm
Core Intuition
When features are collinear or , ordinary least squares is ill-conditioned or non-unique. Ridge regression adds a quadratic penalty that "rounds" the eigenvalues of , stabilizing inversion. Lasso adds an absolute-value penalty that drives some coefficients to exactly zero, performing automatic feature selection.
Ridge vs Lasso Geometry
Ridge Regression: Derivation
The ridge objective:
Taking the gradient and setting to zero:
The matrix is always invertible for , even when is singular.
Spectral Analysis of Ridge
Let with singular values . Then:
Shrinkage factor: .
- Directions with large (strong signal): → barely shrunk.
- Directions with small (noise): → heavily shrunk.
- Ridge acts as a soft spectral filter.
Ridge Bias-Variance Tradeoff
Bias. where is the true parameter.
Variance. .
The MSE is minimized at whenever — ridge always improves over OLS in terms of MSE (a consequence of the Gauss–Markov theorem not applying to MSE under bias).
Lasso Regression: Formulation
The L1 penalty is convex but not differentiable at .
Subgradient Optimality and Sparsity
The optimality condition uses the subdifferential:
where .
For coordinate , let (partial residual correlation):
Sparsity mechanism: If the correlation between feature and the residual is smaller than in magnitude, the coefficient is set to exactly zero.
Coordinate Descent for Lasso
Algorithm. Repeat until convergence:
For :
- Compute partial residual:
- Update:
where is the soft-thresholding operator.
Convergence. Coordinate descent converges to the global minimum because the Lasso objective is convex (but not strictly convex when , so the solution may not be unique).
The Regularization Path
As decreases from (all coefficients zero) to 0:
- Coefficients enter the model one by one at breakpoints.
- The path is piecewise linear (LARS algorithm exploits this).
- Ridge path: coefficients shrink continuously, never reach zero.
- Lasso path: coefficients shrink and hit zero at finite .
Geometric Interpretation
Constrained form (equivalent by Lagrangian duality):
- Ridge: minimize subject to
- Lasso: minimize subject to
The L2 constraint is a sphere — the ellipsoidal loss contours touch it smoothly, rarely at coordinate axes. The L1 constraint is a diamond — contact occurs at vertices (coordinate axes), producing zeros.
Model Selection: Choosing Lambda
The optimal is selected via cross-validation:
- For a grid of values
- For each , compute -fold CV error
- Select minimizing CV error (or "one-SE rule": largest within one standard error of minimum)
Information criteria (AIC, BIC) can also be used:
Common Pitfalls
Pitfall 1. Applying Lasso without standardizing features. L1 penalizes equally for all ; features on larger scales get penalized more in absolute terms.
Pitfall 2. Expecting Lasso to handle groups of correlated features. It tends to select one and zero out the rest. Use Elastic Net for grouped selection.
Pitfall 3. Comparing ridge and Lasso MSE without context. Ridge is better when all features contribute; Lasso wins when true model is sparse.
Summary
- Ridge adds : always has closed-form, shrinks all coefficients, stabilizes ill-conditioning.
- Lasso adds : produces sparse solutions, solved by coordinate descent.
- Sparsity comes from the geometry of the L1 ball (corners at coordinate axes).
- Both can be seen as constrained optimization with different constraint sets.
- Choose via cross-validation.
Exercises
Exercise 1. Starting from the SVD , derive equation (3) for the ridge solution.
Exercise 2. Show that ridge always reduces variance relative to OLS: .
Exercise 3. For orthonormal (), derive the closed-form Lasso solution and compare with ridge.
Exercise 4. Prove that is the smallest for which .
Exercise 5. Show that Elastic Net can be reformulated as a Lasso on an augmented dataset.