Regularization
Regularization adds a penalty on the coefficients of a regression model, trading a small amount of bias for a large reduction in variance. The penalized objective is
where is the regularization strength and is a penalty function. The two canonical choices are the ridge (or ) penalty , and the lasso (or ) penalty . Their elastic net combination blends the two.Ridge has a closed-form solution
obtained by minimizing the augmented normal equations. The added makes the matrix invertible even when is singular, which is exactly what happens when predictors are collinear or when there are more predictors than observations (). Lasso has no closed form because is non-differentiable at zero, but coordinate descent and proximal gradient methods solve it efficiently. The non-differentiability is the feature, not the bug: the kink at zero is what produces sparse solutions, where many are exactly zero rather than just small.Both estimators are biased, with the bias scaling with . As they reduce to OLS; as they shrink toward zero. The that minimizes out-of-sample prediction error is chosen by cross-validation. Predictors should be standardized to unit variance before fitting so the penalty acts comparably across coefficients with different natural scales.
Standardize Before Regularizing or treats every coordinate of the same way, so a coefficient measured in millimeters is penalized the same as one measured in kilometers. Without standardization the regularizer behaves arbitrarily, depending on the units of each predictor. Standard practice: center every column of to mean zero and scale to unit variance before fitting, leave the intercept unpenalized, and rescale the coefficients back at the end.
The penalty
Intuition
OLS is unbiased but has high variance when predictors are correlated or numerous. Two correlated predictors can have OLS coefficients with enormous standard errors, even flipping sign across resamples, because the data cannot pin down which one carries the signal. Regularization fixes this by adding a penalty that pulls coefficients toward zero, sacrificing unbiasedness for stability. The bias-variance trade-off has a sweet spot: a small amount of shrinkage reduces variance much faster than it adds bias, so the mean squared prediction error decreases.
The geometric picture is the most useful one. The OLS solution is the unconstrained minimum of the elliptical cost surface , which has level sets that are ellipses around . The regularized solution adds the constraint that lies in a ball: an ball for ridge, an ball (a diamond in two dimensions) for lasso. The penalized estimate is where the cost ellipse first touches the ball. Because the ball has corners on the coordinate axes, the touching point often lands on a corner, where some coordinates are exactly zero. The ball is smooth, so the touching point generically has all coordinates non-zero but shrunken. That single geometric difference, smooth ball versus corners, is why lasso produces sparse solutions and ridge does not.
The Bayesian interpretation makes this even cleaner. Ridge is the maximum-a-posteriori estimate under a Gaussian prior with , and lasso is the MAP under a Laplace prior . Larger corresponds to a tighter prior around zero. So choosing by cross-validation amounts to learning how much to trust the prior versus the data.
Properties
(Ridge Closed Form) The -penalized objective has a unique solution computable in one step.
Writing the augmented objective as and setting the gradient to zero gives the modified normal equations , with the explicit solution
Because is positive definite for any , the inverse always exists, even when alone is singular (when or when columns are exactly collinear). Diagonalizing through the singular value decomposition writes the solution as , showing that ridge shrinks each principal component of by the factor . Components with small singular values, the ones OLS amplifies most, are shrunk most aggressively.
(Lasso Has No Closed Form But Solves Efficiently) The penalty is non-differentiable at zero, but the objective is convex and decomposes coordinate-wise.
The lasso objective is convex in , so a global minimum exists, but the absolute value’s kink prevents a closed-form expression. The standard solver is coordinate descent: cycle through coordinates and update each by holding the others fixed, which reduces to a one-dimensional problem with the closed-form soft-threshold solution
where is the partial residual. The soft-threshold function leaves large values alone, shrinks moderate ones, and crushes small ones to exactly zero. Iterating to convergence gives the lasso solution; LARS and proximal gradient methods are alternatives for large-scale problems.
(Sparsity) Lasso produces solutions with many exactly-zero coefficients; ridge does not.
The geometric reason is that the ball has corners on the coordinate axes. When the OLS cost ellipse expands outward from until it first contacts the ball, the contact point is generically at a corner because corners stick out the furthest in any given direction. A corner where the th coordinate axis touches has for all the other coordinates. The ball, by contrast, is perfectly smooth, so the contact point generically lies in the relative interior of a face and has no coordinates exactly zero. In high dimensions the lasso typically selects a number of active coefficients close to ; ridge keeps all coefficients non-zero. Sparsity is what makes lasso useful for variable selection: the non-zero coefficients identify a subset of “active” predictors, providing a built-in feature-selection mechanism that ridge lacks.
(Bias-Variance Trade-off) Both estimators are biased, but their variance is much smaller than OLS for moderate .
Decomposing the prediction MSE as , OLS sits at the bias-zero, high-variance extreme. Adding a small introduces a small bias proportional to but reduces the variance by a much larger amount, lowering the total MSE. The improvement is most dramatic when predictors are highly collinear or when is comparable to , the regimes where OLS variance is worst. As grows past its optimum the bias term begins to dominate and MSE rises again. Cross-validation finds the sweet spot empirically.
(Effective Degrees of Freedom) Regularized fits use fewer degrees of freedom than OLS, and the savings can be quantified.
For ridge, the effective degrees of freedom is
where are the singular values of . At this equals (full OLS); as it shrinks toward zero. For lasso, the effective degrees of freedom equals the number of non-zero coefficients in the fit (Zou-Hastie-Tibshirani, 2007). These quantities replace the parameter count in information criteria like AIC and BIC, allowing fair model comparison between fits at different .
(Scale Equivariance) Ridge and lasso are not scale-invariant; predictors must be standardized before fitting.
OLS is invariant to rescaling: multiplying column of by 100 simply divides by 100, leaving fitted values unchanged. Ridge and lasso are not, because the penalty or treats every coefficient on equal footing. A coefficient on a small-scale predictor (already large in magnitude to compensate for its small scale) is penalized more heavily than one on a large-scale predictor. The fix is to standardize: center each column of to mean zero and scale to unit variance before fitting, leave the intercept unpenalized (subtract from for the same reason), and rescale coefficients back to the original units after fitting. This is what every production library does by default.
(Elastic Net) Combines ridge stability with lasso sparsity.
When predictors are highly correlated, lasso has a quirk: it tends to pick one representative from each correlated group and zero the rest, somewhat arbitrarily. Ridge keeps all of them shrunken together. The elastic net penalty
combines the two, controlled by a mixing parameter . The component encourages correlated predictors to enter the model together; the component still produces sparsity. For most applied problems with correlated predictors, elastic net outperforms either pure ridge or pure lasso, with chosen by cross-validation alongside .
(Bayesian Interpretation) Ridge and lasso are MAP estimates under Gaussian and Laplace priors.
Under the Gaussian likelihood , placing a Gaussian prior produces a posterior whose mode is the ridge estimate with . A Laplace prior produces lasso with . The interpretation is that the regularizer encodes a prior belief that coefficients are small, and the strength encodes how confident that belief is. This is also why deep-learning practitioners call regularization weight decay: each gradient step shrinks weights by a factor of before applying the data gradient, mirroring the pull of a Gaussian prior toward zero.
Examples
Two correlated predictors
Two predictors are nearly identical: , with the true model . Compare OLS, ridge, and lasso fits.
What each estimator does on one resample and on another, since the data cannot distinguish "all the weight on " from "split between them." The fitted values are similar but the individual coefficients have huge standard errors. Ridge with moderate produces a stable answer like , splitting the credit evenly between the two collinear predictors. Lasso typically picks one of them: or , depending on tiebreaks. Elastic net interpolates: it identifies that both predictors are active and gives them similar but not identical weights. The right choice depends on whether you want stability (ridge), sparsity (lasso), or both (elastic net).
OLS gives wildly unstable estimates: maybe
regime
A genomic study has patients and gene expression measurements as predictors of a clinical outcome. OLS is undefined because is singular.
Approach is invertible, and the prediction is reasonable but uses every gene. Lasso also produces a unique solution and selects at most non-zero coefficients, identifying a sparse subset of genes that explain the outcome; this set is interpretable for downstream biological investigation. In practice, elastic net is preferred over pure lasso here, because correlated genes (e.g., from the same pathway) often need to enter the model together rather than have one chosen arbitrarily. Cross-validation picks and jointly. The selected gene list is typically reported as candidates for follow-up rather than as definitive biomarkers, since the lasso's selection is sensitive to noise in regimes.
Ridge produces a unique solution because
Polynomial regression
Fit with to a smooth function observed with noise.
Without and with regularization smooths the fit dramatically: high-degree coefficients shrink toward zero, and the resulting curve approximates the true smooth function. Lasso would set most high-degree coefficients to exactly zero, effectively performing automatic degree selection by keeping only the polynomial terms the data justify. This is the canonical demonstration that regularization controls overfitting even when the model is grossly over-parameterized.
Without regularization, OLS fits a wildly oscillating polynomial that interpolates the training points almost exactly but predicts terribly between them, the classic Runge phenomenon. The high-degree coefficients are huge and oscillate in sign. Ridge with a CV-chosen
See Also
- 1.2. Linear Regression: the unregularized OLS estimator that ridge and lasso shrink toward zero.
- 1.2a. Multiple Linear Regression: the matrix form ridge and lasso are built on top of.
- 1.4. Nonlinear Regression: regularization extends to nonlinear least squares with the same penalty terms.
- 1.6. Cross-Validation: how (and for elastic net) are chosen in practice.
- 3.8.1 Bayesian Linear Regression: ridge and lasso as MAP estimates under Gaussian and Laplace priors.
- 2.4 Time Series Regression: how these regularizers are applied to wide time-series designs (lagged predictors, Fourier bases, VAR models).