Phase 11 - Lesson 11.4

Regularization: Ridge and Lasso

Shrinking coefficients on purpose - the closed-form ridge estimator, the sparsity of the lasso, and why bias buys out-of-sample accuracy.

⏱ 50 min● Intermediate🔗 Prereqs: 11.2, 11.3, 10.x convexity
↖ Phase 11 hub
Builds on: 11.2 showed collinearity destabilizes OLS; 11.1 showed bias can lower MSE.
Leads to: The same penalized-likelihood idea underlies penalized logistic regression and elastic nets.

Learning Objectives

Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.

Key Vocabulary

Ridge regression
Least squares with an \(\ell_2\) penalty \(\lambda\|\beta\|_2^2\); shrinks coefficients toward zero, never exactly to zero.
Lasso
Least squares with an \(\ell_1\) penalty \(\lambda\|\beta\|_1\); performs shrinkage and variable selection (exact zeros).
Regularization path
The trajectory of \(\hat\beta(\lambda)\) as the penalty varies from 0 (OLS) to \(\infty\) (all zero).
Soft-thresholding
The operator \(S_\lambda(z)=\text{sign}(z)(|z|-\lambda)_+\); the lasso solution under orthonormal predictors.
Shrinkage factor
In the SVD basis, ridge multiplies the \(j\)th component by \(d_j^2/(d_j^2+\lambda)\in(0,1)\).
Elastic net
A blend \(\alpha\|\beta\|_1+(1-\alpha)\|\beta\|_2^2\) combining lasso sparsity with ridge stability under collinearity.
Effective degrees of freedom
For ridge, \(\sum_j d_j^2/(d_j^2+\lambda)\le p\); complexity falls smoothly as \(\lambda\) rises.

Intuition & Motivation

Intuition
OLS trusts the data completely: it will chase any wiggle, and when predictors are nearly collinear it produces enormous, sign-flipping coefficients that cancel each other and generalize terribly. Regularization adds a spring that pulls coefficients back toward zero. You pay a little bias - the pull is systematic - but you buy a large cut in variance, and in the low-signal, highly-correlated world of financial predictors that trade is almost always worth making.

Ridge uses a round \(\ell_2\) spring: it shrinks everything smoothly and keeps all predictors. Lasso uses a diamond-shaped \(\ell_1\) constraint whose corners sit on the axes, so the solution often lands exactly on an axis - setting some coefficients to precisely zero. That geometry is why lasso selects variables and ridge merely shrinks them.

Ridge: penalized least squares with a closed form

Ridge solves, for a tuning parameter \(\lambda\ge0\) (predictors standardized, intercept unpenalized):

\[\hat\beta_{\text{ridge}}=\argmin_\beta\ \|y-X\beta\|_2^2+\lambda\|\beta\|_2^2.\] (11.9)
Worked Example - Closed form and why it always exists
1
Gradient: \(-2X^\top(y-X\beta)+2\lambda\beta=0.\)
2
Rearrange: \((X^\top X+\lambda I)\beta=X^\top y.\)
3
Solve: \(\hat\beta_{\text{ridge}}=(X^\top X+\lambda I)^{-1}X^\top y.\)
4
Even if \(X^\top X\) is singular (collinear or \(p\gt n\)), adding \(\lambda I\) makes it positive definite, so ridge is always well-defined - unlike OLS.

In the SVD \(X=UDV^\top\), the fitted values become \(\hat y=\sum_j u_j\,\frac{d_j^2}{d_j^2+\lambda}\,u_j^\top y\). Each principal direction is multiplied by a shrinkage factor \(d_j^2/(d_j^2+\lambda)\in(0,1)\): directions with small singular values \(d_j\) (the noisy, collinear directions) are shrunk hardest. Ridge is ‘soft PCA regression’.

Lasso: the \(\ell_1\) penalty and sparsity

Replace the \(\ell_2\) penalty with \(\ell_1\):

\[\hat\beta_{\text{lasso}}=\argmin_\beta\ \tfrac12\|y-X\beta\|_2^2+\lambda\|\beta\|_1.\] (11.10)

There is no closed form in general (the objective is convex but nondifferentiable at zero), but with orthonormal predictors (\(X^\top X=I\)) each coefficient decouples and the solution is soft-thresholding of the OLS estimate:

\[\hat\beta^{\text{lasso}}_j=S_\lambda(\hat\beta^{\text{ols}}_j)=\text{sign}(\hat\beta^{\text{ols}}_j)\,\big(|\hat\beta^{\text{ols}}_j|-\lambda\big)_+.\] (11.11)

Small coefficients (below \(\lambda\)) are set to exactly zero; larger ones are pulled toward zero by \(\lambda\). Ridge, by contrast, multiplies by \(1/(1+\lambda)\) - it never zeroes anything. Geometrically the \(\ell_1\) ball has corners on the axes, so the first contact between the residual ellipse and the constraint ball tends to occur at a corner: a sparse solution.

PropertyRidge (\(\ell_2\))Lasso (\(\ell_1\))
Closed formYes: \((X^\top X+\lambda I)^{-1}X^\top y\)No (convex program)
Sets coefficients to 0NeverYes (variable selection)
Handles \(p\gt n\)YesYes (selects \(\le n\))
Correlated predictorsShares weight, stableMay pick one arbitrarily
Best whenMany small effectsFew strong effects (sparse truth)
Key Idea
Both estimators are biased on purpose. As \(\lambda\) rises, bias grows and variance falls; the CV-optimal \(\lambda\) sits where their sum (test MSE) is smallest. For weak, noisy signals the optimum is far from \(\lambda=0\) - OLS is usually the wrong default in quant modeling.

Interactive: ridge shrinkage in action

Common Mistakes to Avoid
  • Forgetting to standardize predictors before penalizing - the penalty is scale-dependent, so raw units silently reweight variables.
  • Penalizing the intercept; it should stay free so shrinkage does not bias the overall level.
  • Treating lasso's selected set as the ‘true’ variables; under correlation it picks one of a group almost arbitrarily and is unstable across resamples.
  • Choosing \(\lambda\) by training error (which always prefers \(\lambda=0\)); it must come from cross-validation.
  • Reading shrunk coefficients as unbiased effect sizes - they are deliberately biased and not valid for classical inference.
Quant Practitioner Tips
  • Default to ridge when predictors are many and correlated (typical factor zoos); default to lasso when you believe few predictors truly matter.
  • Use the elastic net when you want sparsity but predictors come in correlated groups - it keeps or drops groups together.
  • Select \(\lambda\) with the one-SE rule on a CV curve for a more parsimonious, robust model.
  • Ridge's closed form makes LOOCV essentially free via the hat-matrix diagonal - exploit it for fast tuning.

Knowledge Check

Q1 Medium
The ridge estimator \((X^\top X+\lambda I)^{-1}X^\top y\) is always well-defined even when OLS is not because:
It ignores collinear columns
Adding \(\lambda I\) makes the matrix positive definite hence invertible
It uses the pseudo-inverse
It drops the intercept
Q2 Medium
Why does the lasso produce exactly-zero coefficients while ridge does not?
Lasso uses a smaller \(\lambda\)
The \(\ell_1\) constraint region has corners on the axes where the solution tends to land
Lasso is not convex
Ridge has no closed form
Q3 Medium
As the penalty \(\lambda\) increases from 0, the bias and variance of the estimator:
Both increase
Bias decreases, variance increases
Bias increases, variance decreases
Both decrease

Practical Exercise

Take orthonormal predictors so \(X^\top X=I\) and let \(z=X^\top y\) be the OLS coefficients. (a) Show ridge gives \(\hat\beta_j=z_j/(1+\lambda)\). (b) Show lasso gives soft-thresholding \(\hat\beta_j=S_\lambda(z_j)\). (c) Contrast their treatment of a tiny coefficient \(z_j=0.01\) versus a large one \(z_j=5\) at \(\lambda=0.1\).

▶ Show full solution

(a) With \(X^\top X=I\), ridge is \((I+\lambda I)^{-1}z=z/(1+\lambda)\) componentwise - uniform proportional shrinkage.

(b) The lasso objective decouples into \(\tfrac12(z_j-\beta_j)^2+\lambda|\beta_j|\). For \(\beta_j\gt 0\) the derivative \(\beta_j-z_j+\lambda=0\) gives \(\beta_j=z_j-\lambda\) (valid while positive); symmetrically for negative; and \(\beta_j=0\) when \(|z_j|\le\lambda\). That is \(S_\lambda(z_j)=\text{sign}(z_j)(|z_j|-\lambda)_+\).

(c) At \(\lambda=0.1\): ridge maps \(0.01\to0.0091\) and \(5\to4.545\) (same 1/1.1 factor - the big coefficient is shrunk in absolute terms much more). Lasso maps \(0.01\to0\) (killed) and \(5\to4.9\) (shifted by a constant \(\lambda\)). Lasso selects (zeros the noise) while lightly biasing the strong signal; ridge keeps everything but proportionally shrinks the strong signal harder.

After the reveal, answer for yourself: Ridge multiplies; lasso subtracts. That single difference is the whole story of shrinkage vs selection.

Lesson Summary

Regularization adds a penalty to least squares, trading a little bias for a large variance reduction. Ridge (\(\ell_2\)) has the closed form \((X^\top X+\lambda I)^{-1}X^\top y\), is always well-defined, and shrinks each SVD direction by \(d_j^2/(d_j^2+\lambda)\) without zeroing anything. Lasso (\(\ell_1\)) has corners on the axes, yielding exact zeros and variable selection (soft-thresholding when orthonormal). For weak, collinear financial signals the CV-optimal penalty is far from zero, so plain OLS is rarely the right choice.

Formula Sheet Additions

Ridge estimator
\[\hat\beta_{\text{ridge}}=(X^\top X+\lambda I)^{-1}X^\top y\]
Closed form; exists even when \(X^\top X\) is singular.
Soft-thresholding
\[S_\lambda(z)=\text{sign}(z)(|z|-\lambda)_+\]
Lasso solution under orthonormal predictors; the source of sparsity.
Error Log Checklist
  • Did I standardize predictors and leave the intercept unpenalized?
  • Did I choose \(\lambda\) by cross-validation, not training error?
  • Am I treating lasso's selection as stable when predictors are correlated (it is not)?
  • Did I avoid interpreting shrunk coefficients as unbiased effect sizes?

Retrieval Practice

Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.

▶ Show retrieval prompts & answers
Q: Write the ridge estimator and explain why it exists when OLS fails.
A: \((X^\top X+\lambda I)^{-1}X^\top y\); the \(\lambda I\) term makes the matrix positive definite even under collinearity or \(p\gt n\).
Q: Why does lasso zero coefficients but ridge does not?
A: The \(\ell_1\) constraint ball has corners on the axes so solutions land there; the \(\ell_2\) ball is smooth so ridge only shrinks proportionally.
Q: How does \(\lambda\) move bias and variance, and how is it chosen?
A: Increasing \(\lambda\) raises bias and lowers variance; pick the \(\lambda\) minimizing cross-validated error, often via the one-SE rule.

Flashcards

Click to flip. These feed the site-wide spaced-repetition queue.

Ridge
\(\arg\min\|y-X\beta\|^2+\lambda\|\beta\|_2^2\) = \((X^\top X+\lambda I)^{-1}X^\top y\); shrinks, never zeroes.
Lasso
\(\arg\min\tfrac12\|y-X\beta\|^2+\lambda\|\beta\|_1\); sparse solutions; soft-thresholding when orthonormal.
Shrinkage factor
Ridge scales SVD component \(j\) by \(d_j^2/(d_j^2+\lambda)\); noisy small-\(d_j\) directions shrunk hardest.

Completion Checklist

Confidence / mastery rating
Personal notes

Source References

This lesson synthesizes and paraphrases concepts from the sources below. No copyrighted text, problem sets, or solutions are reproduced. Return to the originals for full depth.