Skip to content

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

Role · kind
Models and algorithmsModel
Level
Intermediate

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

See it on the full map

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 mathRidge: min⁡w∥y−Xw∥2+λ∥w∥22Lasso: min⁡w∥y−Xw∥2+λ∥w∥1\text{Ridge: } \min_w \lVert y - Xw \rVert^2 + \lambda \lVert w \rVert_2^2 \qquad \text{Lasso: } \min_w \lVert y - Xw \rVert^2 + \lambda \lVert w \rVert_1

Ridge has a closed form, w=(X⊤X+λI)−1X⊤yw = (X^\top X + \lambda I)^{-1} X^\top y; the added λI\lambda I 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 λ\lambda trades fit against simplicity: λ=0\lambda = 0 is ordinary regression, a huge λ\lambda 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

  1. Q01

    Which penalty tends to set weights to exactly zero?

    Show answer

    B: L1 (lasso)

  2. Q02

    What happens as the penalty strength λ grows very large?

    Show answer

    A: Weights shrink toward zero and the model underfits

Go deeper