Penalized Regression (Ridge and Lasso)

Context: FIT2086_MOC · the stable alternative to all-or-nothing subset search in Model Selection and Information Criteria (AIC, BIC) · shrinks least-squares coefficients to trade a little bias for less variance (Bias-Variance Tradeoff (Underfitting vs Overfitting)) · chosen by Cross-Validation · in R ➔ Penalized Regression in R (glmnet) · one-parameter derivation ➔ Shrinkage Estimator of the Mean

Quick Revision

  • 🎯 Objective: minimise on standardised predictors ➔ sets model complexity ➔ pick by CV, refit on all the data.
  • 📦 Core Components: Ridge ➔ stable, never exactly zero | Lasso ➔ sparse, performs variable selection.
  • ⚠️ Key Constraint: ridge cannot select variables; lasso can, but biases large coefficients and struggles with correlated predictors.

📝 How It Works

1. Statistical Instability of Subset Selection

  • Conventional methods ➔ all-subsets (score every combination), forward selection, backward selection — intuitive but expensive or unstable.
  • Their problems ➔ statistically unstable (small data change ⟹ big model change) · multiple-testing false positives (Multiple Testing and the Bonferroni Correction) · all-subsets infeasible for moderate-to-large · stepwise hurt by correlated predictors and slow for large .
  • Diabetes experiment ➔ , (AGE, SEX, BMI, BP, S1–S6); remove one random sample, search all subsets for the smallest CV error, repeat 4 times (same CV partitioning rule each time).
TestAGESEXBMIBPS1S2S3S4S5S6
1✓✓✓✓✓✓✓
2✓✓✓✓✓✓
3✓✓✓✓✓✓✓✓
4✓✓✓✓✓✓✓✓
  • Reading ➔ one observation of 354 flips AGE, S4, S5 in and out ➔ the all-or-nothing include/exclude decision makes the “best” model jump with tiny data changes.

2. Penalised Least Squares

  • Objective ➔ penalise the coefficients instead of choosing subsets:
  • Contrast ➔ ordinary least squares minimises goodness-of-fit () only.
  • Penalty choice ➔ increases with ; the sum runs over , so the intercept is not penalised — it is the baseline prediction, and shrinking it towards would bias every prediction without reducing complexity.
  • Generalises ➔ logistic regression becomes penalised maximum likelihood (penalty added to the NLL).
  • Standardise first ➔ penalising “large” coefficients only makes sense if size means strength, but ‘s size depends on the predictor’s scale ⟹ require and via ⟹ larger means stronger association; means no association.

3. The Hyperparameter and the Path

  • ➔ user-chosen hyperparameter controlling penalty strength.
  • Limits ➔ ⟹ least squares; larger ⟹ smaller.
  • Complexity dial ➔ varying traces a path of models; moving towards small the models become more complex.
  • Choosing ➔ (1) vary over a grid; (2) for each, estimate prediction error by CV; (3) take the with smallest CV error; (4) refit with that on all the data. AIC/BIC can replace CV.
  • Implementations ➔ R: the glmnet package; MATLAB: lasso(), lassoglm().

4. Ridge Regression

  • Penalty ➔ : — a parabola in , steeper for larger .
  • Strengths ➔ very quick even for large and · very stable, low-variance estimates · well suited to multicollinearity.
  • Weakness ➔ cannot set a coefficient exactly to zero ⟹ no variable selection.
  • Path shape ➔ coefficients shrink smoothly towards zero as grows.

5. Lasso Regression

  • Penalty ➔ : — a V with its corner at .
  • Strengths ➔ efficient algorithms · coefficients can be exactly zero ⟹ a sparse estimator that performs variable selection.
  • Weaknesses ➔ biased estimates for large coefficients · correlated predictors are problematic · can overfit (include unassociated predictors).
  • Path shape ➔ coefficients hit zero one by one as grows; reading the path right-to-left is the order predictors enter.

6. Why Penalisation Helps

  • Advantages ➔ increased statistical stability · works when · better behaviour with correlated predictors (ridge particularly).
  • Multicollinearity ➔ predictors highly correlated ⟹ hard to separate their relationships with the target ⟹ inflated variance in least squares, and dramatically more instability in stepwise methods.
  • Bias–variance motivation ➔ if the linear model is correct, OLS is unbiased but can have high variance; shrinking towards zero deliberately adds bias to cut variance ⟹ a good lowers .
  • Irreducible error untouched ➔ in prediction error does not depend on .
  • Hand-derivable case (Studio 8) ➔ ridge on an intercept alone gives : bias , variance ➔ Shrinkage Estimator of the Mean.
  • Small- evidence (Studio 8) ➔ Pima, , : plain glm AUC · backward BIC · lasso · ridge ⟹ penalisation degrades gracefully where stepwise collapses; at lasso only matches stepwise ➔ Penalized Regression in R (glmnet).

⚖️ Core Decision Matrix

MethodPenaltyExact zeros?StabilityCorrelated predictorsMain weakness
Subset / stepwisenone (discrete in/out)yesunstablemakes stepwise worseinfeasible or slow for large
Ridgenovery stablehandles wellno variable selection
Lassoyes (sparse)more stable than subsetsproblematicbiases large coefficients; can overfit

When It Flips: need a reduced predictor set ➔ lasso; predictors heavily correlated and only prediction matters ➔ ridge.

📊 Exam Execution Trace & Applied Exercises

Manual Execution Trace

Lasso on the degree-20 polynomial example (, true order 5), decreasing :

CV errorDF (non-zero terms)
(flat line)
  • Read it ➔ falls monotonically as (in-sample fit always improves) while CV error is U-shaped ➔ selected with 4 active terms; beyond it explodes and the curve wiggles (overfit).

⚠️ Common Mistakes

  • 💡 Skipping standardisation ➔ the penalty then punishes predictors for their units, not their weakness.
  • 💡 Choosing by ➔ RSS always prefers ; use CV (or AIC/BIC).
  • 💡 Claiming ridge selects variables ➔ ridge shrinks but never zeroes; only lasso gives exact zeros.
  • 💡 Reporting the CV-fold fit ➔ after picking , refit on all the data.

🧠 Active Recall