Visual explainer
Ridge & Lasso Regularisation
Add a regularization penalty on parameter magnitude to control model variance: contrast smooth L2 ridge shrinkage against sparse L1 lasso feature selection.
When linear models fit noisy or collinear datasets where feature count approaches sample size (), the empirical covariance matrix becomes ill-conditioned. Unconstrained Ordinary Least Squares (OLS) produces wildly exploding, opposing weights () that cancel each other out to memorize idiosyncratic training noise. While training MSE reaches zero, test error explodes to due to severe model variance.
Charge Rent on Size
Regularization remedies coefficient explosion by penalizing weight magnitude directly inside the objective function:
The total loss balances empirical fit against model complexity. For instance, with training MSE , tuning parameter , and weight size metric , the regularizer charges a complexity rent of , bringing the total loss bill to . Tuning sweeps the Pareto frontier from pure unconstrained OLS () to total parameter extinction ().
Ridge Shrinks Gently
Ridge regression imposes an Euclidean penalty . In the orthonormal setting, the closed-form analytical solution scales unpenalized OLS coefficients by a smooth shrinkage factor:
With baseline and , the weight shrinks by to . Geometrically, the constraint boundary forms a smooth circular sphere (). Elliptical loss contours touch this smooth arc off-axis, pulling weights continuously toward the origin without ever setting them to exact zero.
Lasso Snaps Clean
Lasso (Least Absolute Shrinkage and Selection Operator) applies an Manhattan penalty , governed by the soft-thresholding operator:
With , a strong predictor with shrinks by to and survives. However, a weak noisy attribute with falls below the threshold () and snaps strictly to . Geometrically, the constraint forms a sharp diamond with pointed corners on the coordinate axes; quadratic loss contours frequently intersect these corners, driving coefficients to absolute zero and performing automated sparse feature selection.
Sparser Tests Better
Evaluating generalization performance on 12 held-out test points proves the statistical dividend of sparsity. A dense unregularized model retaining all 10 candidate features captures spurious noise correlations, failing on 5 of 12 test instances (error rate ). The sparse Lasso model, which zeroes out 7 irrelevant noise dimensions and retains only the 3 true signal predictors, misses only 2 of 12 test instances (error rate ), achieving a reduction in test error.
Match Penalty to Field
Selecting between penalties depends on the underlying data-generating distribution:
- Ridge (): Retains all predictors, shrinking coefficients smoothly. Optimal for dense regimes where many predictors each exert small, distributed effects (e.g., climate metrics, image pixels).
- Lasso (): Enforces true parameter sparsity. Optimal when the true signal is sparse, concentrated in a few dominant features among dozens of uninformative measurements.
- ElasticNet: Blends and penalties (), grouping correlated variables together while maintaining sparse feature selection.
Where It Breaks
Lasso encounters a severe failure mode when handling highly collinear features. Consider two identical predictors, such as height measured in centimeters () and height measured in inches (). Because the diamond has flat planar facets between corners, the optimization problem becomes non-strictly convex: Lasso arbitrarily selects one twin at full weight () and zeroes out the other (). Minor data perturbations cause the selected feature to flip randomly across runs, destroying interpretability. In such scenarios, Ridge or ElasticNet should be preferred, as their strictly convex curvature divides weight evenly across correlated twins ().
The Quick Version
- Exploding weights: Unconstrained OLS on noisy or collinear data drives weights to massive cancelling values, causing extreme test variance.
- Size penalty: Regularization minimizes , charging a complexity rent to constrain parameter growth.
- Ridge (): Smooth circular constraint shrinks weights by (), keeping all features active.
- Lasso (): Sharp diamond constraint uses soft-thresholding, shrinking to while snapping strictly to .
- Sparsity dividend: Dropping 7 noisy dimensions cuts held-out test error from (5 misses) to (2 misses).
- Taxonomy: Use Ridge for dense, distributed effects; use Lasso for sparse feature selection; use ElasticNet for correlated groups.
- Collinear twins limit: Lasso randomly breaks ties between identical predictors, causing unstable feature selection that Ridge resolves.