What is ridge regression?
Last updated
Ridge regression is linear least squares with an L2 penalty on the coefficients. It shrinks weights toward zero, trading a little bias for a large reduction in variance, which is especially useful with correlated features or many predictors.
Objective:
min_w ||y − Xw||² + λ||w||², where λ ≥ 0 controls the strength of the penalty.λ = 0 gives OLS. As λ → ∞, w → 0.
Key properties:
Closed form:
w = (XᵀX + λI)⁻¹Xᵀy. It is always unique for λ > 0.It shrinks coefficients but doesn't set them exactly to zero, so it performs no feature selection (unlike Lasso).
It stabilizes estimates under multicollinearity and works when p > n.
Interpretations:
Constrained: minimize RSS subject to
||w||² ≤ t.Bayesian: the MAP estimate under a Gaussian prior
w ~ N(0, σ²/λ · I).
Practical notes:
Standardize features first: the penalty is scale-dependent.
Don't penalize the intercept (center the data instead).
Choose λ by cross-validation (e.g.
RidgeCVin scikit-learn).