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).
| Test | AGE | SEX | BMI | BP | S1 | S2 | S3 | S4 | S5 | S6 |
|---|---|---|---|---|---|---|---|---|---|---|
| 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
glmnetpackage; 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
glmAUC · backward BIC · lasso · ridge ⟹ penalisation degrades gracefully where stepwise collapses; at lasso only matches stepwise ➔ Penalized Regression in R (glmnet).
⚖️ Core Decision Matrix
| Method | Penalty | Exact zeros? | Stability | Correlated predictors | Main weakness |
|---|---|---|---|---|---|
| Subset / stepwise | none (discrete in/out) | yes | unstable | makes stepwise worse | infeasible or slow for large |
| Ridge | no | very stable | handles well | no variable selection | |
| Lasso | yes (sparse) | more stable than subsets | problematic | biases 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 error | DF (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
Why is all-subsets selection unstable, and why does shrinkage help?
Answer
- Short answer: Each predictor is either fully in or fully out, so a tiny data change can flip the choice and the whole model jumps; a penalty moves coefficients continuously, so small data changes give small coefficient changes.
- Why: Discrete vs continuous ➔ the diabetes experiment flipped AGE/S4/S5 after removing one of 354 points; varies smoothly with the data and with .
Why can lasso set coefficients exactly to zero while ridge cannot?
Answer
- Short answer: The penalty keeps a constant pull towards zero even for tiny coefficients (its V has a corner at ), while the penalty’s pull vanishes as (flat-bottomed parabola).
- Why: Penalty shape ➔ vs — the lecture plots show the V and the parabola; the paths show lasso coefficients hitting zero and ridge ones only approaching it.
If OLS is unbiased, how can a biased penalised estimator predict better?
Answer
- Short answer: Error is ; shrinkage adds a little bias but can remove much more variance.
- Why: Bias–variance trade ➔ controls the exchange; is unaffected, so the whole gain comes from the variance term.