Ridge and Lasso Regression
Linear regression with a penalty on large weights: ridge shrinks all weights a little, lasso pushes useless ones to exactly zero.
Also ridge regression · lasso · Tikhonov regularization · elastic net · L1 regression · L2 regression
Hoerl and Kennard, 1970 (ridge); Tibshirani, 1996 (lasso)
Fitting a line while someone charges you for every unit of slope you use. Ridge makes you use a bit less of everything; lasso makes you drop the features that aren't worth paying for.
Where it fits
+All relationships as a list
Is a kind of / part of
Uses / built on
Evolved from
How it works
Plain linear regression picks the weights that fit the training data best. With many features or few rows, “best” often means huge, unstable weights that chase noise: overfitting.
Ridge and lasso add a price for large weights, the idea of regularization applied to linear models:
- Ridge (L2) charges the square of each weight. Big weights are expensive, so everything shrinks smoothly toward zero, but rarely reaches it.
- Lasso (L1) charges the absolute value. That price has a sharp corner at zero, so weights of weak features land exactly on zero: the model selects features for you.
The math
Ridge has a closed form, ; the added also makes the matrix invertible when features are correlated. Lasso has no closed form and is solved with coordinate descent. Elastic net adds both penalties.
The strength trades fit against simplicity: is ordinary regression, a huge flattens the model toward a constant. Choose it with cross-validation, and scale the features first so the penalty is fair to all of them.
Everyday use cases
- Case 01
Picking the few features that matter
Lasso finds the handful of useful predictors among hundreds of candidate marketing signals.
- Case 02
Stable estimates with correlated inputs
Ridge keeps a house price model sensible when size, rooms and floor area all say roughly the same thing.
Strengths, weaknesses and when to use it
Strengths
- Fights overfitting with one easy-to-tune knob.
- Lasso gives sparse, readable models; ridge handles correlated features gracefully.
Weaknesses
- Still linear: no curves unless you add features.
- Features must be scaled, or the penalty treats them unfairly.
- Lasso picks one of a group of correlated features somewhat arbitrarily.
When to use itWhenever you fit linear regression with many features or little data. Ridge as the default, lasso when you want feature selection.
Compare with
Check yourself
- Q01
Which penalty tends to set weights to exactly zero?
Show answer
B: L1 (lasso)
- Q02
What happens as the penalty strength λ grows very large?
Show answer
A: Weights shrink toward zero and the model underfits