45.06.03 · mathematical-statistics / 06-high-dimensional-regularization

Ridge Regression and Shrinkage Estimation

shipped3 tiersLean: none

Anchor (Master): Hastie, Tibshirani & Friedman 2009 The Elements of Statistical Learning 2e (Springer) §3.4 and §3.7 (ridge, the Bayesian/Gaussian-prior view, shrinkage methods compared); Hoerl & Kennard 1970 Technometrics 12 (1), 55-67 and 69-82; Hastie, Tibshirani & Wainwright 2015 Statistical Learning with Sparsity (CRC) Ch. 2 (the ell_1 contrast that ridge sets up)

Intuition Beginner

Least squares hands you the weights that fit your data best, full stop. That sounds ideal, but it has a failure mode: when your predictors are nearly redundant — two columns of data that say almost the same thing — the fitting machine cannot decide how to split the credit between them. It compensates by inventing huge offsetting weights, a giant positive one on the first predictor and a giant negative one on the second. These weights are wildly unstable: collect a fresh dataset and they swing somewhere completely different. The fit looks great on the data you have and predicts terribly on data you do not.

Ridge regression fixes this by adding a penalty for large weights. Instead of asking only "how small can I make the total squared miss?", it asks "how small can I make the total squared miss plus a charge on the size of the weights?" The charge is tuned by a dial. Turn the dial to zero and you are back to plain least squares. Turn it up and the weights are pulled toward zero, gently at first, harder as you keep turning.

Why does pulling the weights toward zero help? Because a small, deliberate amount of being-wrong-on-average buys a large reduction in instability. You accept a fit that is slightly off the true relationship in exchange for a fit that barely moves when the data changes. This is the bias-variance bargain from the previous unit, made into a knob you can turn.

The everyday image is a budget. Least squares spends without limit to match the data; ridge puts the weights on an allowance. Under the allowance, the fit cannot chase every quirk of one dataset, so it tracks the stable, repeatable signal instead.

Visual Beginner

Dial setting (penalty strength) What happens to the weights Bias Variance Typical outcome
Zero exactly the least-squares weights none high (can be huge if predictors overlap) overfits, unstable
Small weights pulled slightly toward zero small lower usually better on new data
Moderate clear shrinkage, stable weights moderate low often the sweet spot
Very large weights crushed toward zero large tiny underfits, predicts the average

The single picture to carry forward: every coefficient path slides toward zero as you raise the penalty, but the directions in your data that carry the most information resist the pull, while the flimsy, redundant directions collapse fast. Ridge does not switch predictors off; it quiets the unreliable ones.

Worked example Beginner

Take two data points and one predictor with no intercept, so the model is . The data are at , and at . Plain least squares picks the slope that minimizes .

The least-squares slope solves the normal equation. The sum of is , and the sum of is , so .

Now add a ridge penalty with dial value . Ridge minimizes . The recipe changes the denominator: it becomes the sum of plus , that is , while the numerator stays . So the ridge slope is .

The penalty has cut the slope exactly in half, from to . Try instead: the denominator is , giving . And gives denominator , so .

What this tells us: the ridge slope is always the least-squares slope scaled down by the factor — the original -sum over itself-plus-penalty. At the factor is (no shrinkage); as grows the factor shrinks toward . The penalty never flips the sign and never sets the slope to exactly zero; it only damps it, and the more penalty you add, the more it damps.

Check your understanding Beginner

Formal definition Intermediate+

Fix a design matrix and response . Assume the predictors are centered and scaled to unit variance and the intercept is fitted separately (so carries no column of ones); the penalty is applied to the slope coefficients only. For a penalty parameter , the ridge regression (or Tikhonov-regularized) estimator is the minimizer of the penalized residual sum of squares

The criterion is a strictly convex quadratic in whenever . Differentiating and setting the gradient to zero gives the regularized normal equations , and since is positive semidefinite, is positive definite for , hence invertible. The estimator is

The decisive structural fact, sharpening the OLS theory 45.06.01: this solution exists and is unique even when is singular — in particular when and ordinary least squares has no unique solution. Adding lifts every eigenvalue of by , curing the rank deficiency. The fitted values are with the ridge hat matrix

which is symmetric but not idempotent (it is not a projection), and the effective degrees of freedom are , decreasing from at to as — the continuous complexity index of 45.06.02.

The singular value view makes the mechanism transparent. Write the thin SVD 01.01.12 with , having orthonormal columns , and the singular values, . The ridge fitted values decompose along the principal directions as

Each coordinate is multiplied by the shrinkage factor . Directions with large singular values (where the data carry strong, well-determined signal) are barely touched; directions with small singular values (where the design is nearly collinear and the OLS coefficient is unstable) are shrunk hard. Ordinary least squares is the case, where every factor equals .

Counterexamples to common slips

  • The ridge hat matrix is not a projection. is symmetric but for ; its eigenvalues lie strictly between and , so is a contraction of toward the origin along principal directions, not an orthogonal projection onto a subspace.
  • Ridge is not scale-invariant. Because the penalty depends on the units of each predictor, rescaling a column changes the solution. Standardizing the predictors before fitting is part of the method, not an optional cleanup; the intercept is excluded from the penalty for the same reason.
  • Existence does not require full rank. The phrase "the ridge solution" is well-posed for any regardless of ; the regularizer guarantees a unique minimizer even when , which is precisely the high-dimensional regime where OLS fails to define one.
  • Shrinkage toward zero is a modeling choice. Ridge shrinks toward the origin only because the prior mean is taken to be zero after centering; shrinking toward any fixed replaces by and changes nothing structural.

Key theorem with proof Intermediate+

Theorem (existence of an improving ridge constant — Hoerl & Kennard 1970). Under the linear model with , , and of full column rank, let be the total mean squared error of the ridge estimator. Then whenever there exists with : ridge strictly beats ordinary least squares in total MSE. The proof follows Hoerl & Kennard [Hoerl 1970] and the SVD presentation of Hastie, Tibshirani & Friedman [Hastie 2009] §3.4.1.

Proof. Rotate to the eigenbasis of . With the SVD , write for the true coefficient in singular coordinates and for the estimator. A direct computation from gives, in coordinate ,

using with . Because is orthogonal, total MSE is the sum of coordinate MSEs, and each coordinate splits as squared bias plus variance 45.06.02:

Write for this sum and differentiate term by term. For the variance part, . For the bias part, . Summing,

Evaluate at : every numerator becomes , so . The squared-bias terms enter through and so contribute nothing to the first derivative at the origin, while the variance terms contribute a strictly negative slope. Since is continuously differentiable and , there is an interval on which . Any in that interval improves on least squares.

Bridge. The proof's engine is the SVD rotation that diagonalizes the problem so that total MSE becomes a sum of one-dimensional bias-variance trade-offs, each governed by the shrinkage factor . This builds toward the full advanced theory below, where the same factor controls effective degrees of freedom and the Bayesian posterior mean, and it appears again in 45.06.06 when the lasso replaces the smooth contraction with a thresholding map. The foundational reason ridge can win is that least squares sits at the boundary of the admissible region — it is the unbiased corner — so its MSE derivative in the bias direction is zero while the variance can only be reduced by moving inward; this is exactly the single-coordinate computation of 45.06.02 Exercise 5 promoted to all directions at once. The result generalises the Gauss-Markov benchmark of 45.06.01 rather than contradicting it: Gauss-Markov ranks OLS first among unbiased linear estimators, and ridge wins only by abandoning unbiasedness, so the central insight is that the unbiasedness constraint — not optimality itself — is what high-dimensional statistics relaxes. Putting these together, ridge is the smooth, always-feasible shrinkage that the bias-variance decomposition predicts must exist.

Exercises Intermediate+

Lean formalization Intermediate+

Mathlib does not yet host the statistical ridge estimator, so no module is wired in (lean_status: none). The intended statement of the closed form and the SVD shrinkage identity, once a least-squares-functional API exists, would read roughly as follows.

-- Intended shape; not part of the current Babel Bible Lean build.
-- Requires: a penalized-least-squares functional and the SVD of a real matrix.
variable {n p : ℕ} (X : Matrix (Fin n) (Fin p) ℝ) (y : Fin n → ℝ) (lam : ℝ)

-- The regularized Gram matrix is positive definite, hence invertible, for lam > 0.
theorem ridge_gram_posDef (hlam : 0 < lam) :
    (Xᵀ * X + lam • (1 : Matrix (Fin p) (Fin p) ℝ)).PosDef := by
  sorry

-- Closed form: the ridge estimator minimizes ‖y - X β‖² + lam ‖β‖².
noncomputable def ridgeHat (hlam : 0 < lam) : Fin p → ℝ :=
  (Xᵀ * X + lam • 1)⁻¹ *ᵥ (Xᵀ *ᵥ y)

theorem ridge_minimizes (hlam : 0 < lam) (β : Fin p → ℝ) :
    ‖y - X *ᵥ ridgeHat X y lam hlam‖^2 + lam * ‖ridgeHat X y lam hlam‖^2
      ≤ ‖y - X *ᵥ β‖^2 + lam * ‖β‖^2 := by
  sorry

the Mathlib gap analysis records what is missing: the penalized-least-squares functional, the proof that is positive definite from Matrix.PosSemidef plus the strictly positive shift, the SVD-coordinate shrinkage identity, and the conjugate-normal posterior-mean computation behind the Bayesian view.

Advanced results Master

The Bayesian derivation places ridge inside a coherent inferential frame. Take the conjugate Gaussian model with prior . The log-posterior in is, up to additive constants,

and maximizing it over is exactly the ridge criterion with . The posterior is itself Gaussian, , so the ridge estimator is simultaneously the maximum-a-posteriori and the posterior-mean estimate; for a Gaussian posterior the two coincide. The penalty strength is the noise-to-prior variance ratio: a tight prior (small , strong belief that coefficients are near zero) forces a large and heavy shrinkage, while a diffuse prior recovers least squares as . This is the forward connection promised by 45.06.02: shrinkage is prior information made quantitative, developed fully in the Bayesian treatment 45.03.02.

Effective degrees of freedom give ridge a calibrated complexity. With , the optimism identity of 45.06.02 yields the in-sample risk surrogate , and substituting an estimate of into Mallows-type criteria or the generalized cross-validation score selects without a held-out set. In practice is chosen by -fold cross-validation over a logarithmic grid: for each candidate the average held-out squared error is computed, and the minimizer (or the largest within one standard error of the minimum, the one-standard-error rule) is taken. Because ridge has a closed form, the entire ridge trace is a smooth path computed once from the SVD, so the cross-validation sweep is cheap.

Kernel ridge regression lifts the method to nonlinear and infinite-dimensional feature maps. Replace each by a feature vector in a (possibly infinite-dimensional) space and penalize there. The closed form, after the matrix push-through identity , becomes , where is the kernel Gram matrix and . The feature map never appears explicitly — only inner products — which is the kernel trick. The estimator lives in the reproducing-kernel Hilbert space generated by , the setting developed in 45.08.01, and the representer theorem guarantees the solution is a finite combination of kernels at the data points.

Ridge sits at one end of a spectrum of penalties. The general bridge penalty recovers ridge at and the lasso at . The qualitative break occurs at : for the penalty is differentiable at the origin and the solution map is a smooth contraction (no exact zeros, as in ridge), while at the penalty has a corner at the origin and the solution map thresholds, producing exact zeros and hence variable selection. The elastic net combines both, inheriting ridge's stability under correlated predictors (it shrinks correlated coefficients together rather than arbitrarily picking one) and the lasso's sparsity. The -versus- contrast that organizes this chapter is the contrast between a contraction and a threshold, exactly the SVD shrinkage of ridge against the soft-thresholding of 45.06.06.

Synthesis. The foundational reason ridge unifies regularization, Bayesian shrinkage, and complexity control is that the SVD diagonalizes the estimator into independent one-dimensional shrinkages, each with factor , so the bias, the variance, the effective degrees of freedom, and the posterior covariance are all functions of that single factor. This is exactly the multivariate promotion of the one-coordinate bias-variance calculation of 45.06.02, and putting these together with the Hoerl-Kennard existence theorem shows that the optimal penalty from the Gaussian prior and the MSE-minimizing penalty from the frequentist trade-off are the same quantity viewed from two sides — the noise-to-signal ratio. The central insight is that ridge generalises ordinary least squares by relaxing the Gauss-Markov unbiasedness constraint of 45.06.01: the contraction toward zero is dual to the prior pull toward zero, and the bridge is the regularized Gram matrix whose eigenvalue lift simultaneously cures collinearity, guarantees existence when , and quantifies the shrinkage. The same machinery, with inner products replaced by kernels, becomes kernel ridge regression and the RKHS theory of 45.08.01; with the smooth penalty replaced by a cornered one, it becomes the sparse selection of 45.06.06.

Full proof set Master

The closed form, the SVD shrinkage identity, the effective-degrees-of-freedom formula, and the Hoerl-Kennard existence theorem are proved in full in the Formal definition, Key theorem, and Exercises sections. The remaining Master claims are recorded here.

Proposition 1 (Ridge as posterior mean under a Gaussian prior). Under and , the posterior is with , so is both the posterior mean and the MAP estimate.

Proof. The log-posterior is . Expanding the quadratic in , the coefficient of the quadratic term is and of the linear term is . A Gaussian density has log-density quadratic form ; matching, and . Hence and . The posterior is Gaussian, so its mean equals its mode, and both equal .

Proposition 2 (Ridge bias and the strict MSE gain at orthonormal design). For with independent across , the ridge MSE is , minimized at .

Proof. By Exercise 4 each coordinate satisfies , so its bias is with squared bias , and its variance is . Summing over gives . Differentiating, the numerator of is proportional to , which vanishes at . Since this is positive whenever , a strictly positive penalty minimizes MSE, recovering the general Hoerl-Kennard conclusion in the orthonormal case with an explicit optimum.

Proposition 3 (Kernel ridge push-through identity). For any feature matrix and , , so the ridge fit is with .

Proof. Both regularized matrices are invertible for . Start from the identity , which holds because each side equals . Left-multiply by and right-multiply by to obtain . Then , and . The estimator depends on only through inner products , so an explicit feature map is never needed.

Proposition 4 (Ridge has no exact zeros at finite ). If has no zero singular values and for the relevant , then for every finite each principal-coordinate ridge estimate is nonzero; coefficients vanish only in the limit .

Proof. The shrinkage multiplier is a quotient of a positive number by the positive number , hence strictly positive for every finite . Multiplying the nonzero data coordinate by a strictly positive scalar gives a nonzero result, so . As the multiplier tends to , so the estimate tends to but attains it only in the limit. The smooth penalty therefore contracts without selecting; exact zeros require the cornered penalty of 45.06.06.

Connections Master

Linear model theory 45.06.01 supplies the OLS estimator, the normal equations, and the hat matrix that ridge regularizes; ridge deliberately relaxes the Gauss-Markov unbiasedness constraint that makes OLS the BLUE there, replacing by to trade unbiasedness for a variance reduction, so ridge is the unbiased benchmark of that unit moved inward off the boundary.

The bias-variance decomposition 45.06.02 is the engine of the existence theorem: the SVD turns total MSE into a sum of per-coordinate squared-bias-plus-variance terms, and the single-coordinate shrinkage computation there (Exercise 5) is exactly the special case proved here as Proposition 2; the effective degrees of freedom that index ridge complexity are the same optimism-linked quantity defined there.

The singular value decomposition 01.01.12 is the structural backbone: rotating into the singular basis diagonalizes the ridge estimator so that each principal direction shrinks independently by , which is why collinear (small-) directions are damped and well-determined (large-) directions are preserved.

Bayesian statistics 45.03.02 reframes ridge as the posterior mean and MAP estimate under a Gaussian prior , with the penalty equal to the noise-to-prior-variance ratio; the deliberate bias of ridge is the prior pull toward zero, and the closed-form Gaussian posterior covariance is the inferential output the frequentist treatment leaves implicit.

The lasso and sparse selection 45.06.06 is the counterpart: replacing the smooth ball by the cornered ball turns ridge's pure contraction into soft-thresholding with exact zeros, so the two methods are the contraction and the threshold ends of the bridge-penalty family, and the elastic net combines them.

Kernel methods and reproducing-kernel Hilbert spaces 45.08.01 are reached by the push-through identity proved here as Proposition 3: kernel ridge regression is ridge in a feature space accessed only through inner products, and the representer theorem of that unit guarantees the solution is a finite kernel expansion at the data points.

Historical & philosophical context Master

Ridge regression was introduced by Arthur Hoerl and Robert Kennard in two companion 1970 Technometrics papers [Hoerl 1970], motivated by the practical instability of least squares for nonorthogonal (collinear) industrial design problems. Their central theorem — that there always exists a positive ridge constant for which the biased estimator has smaller total mean squared error than least squares — turned a numerical regularization device into a statistical method with a precise optimality justification. The diagnostic they proposed, the ridge trace plotting each coefficient against , made the stabilization visible and remains in use. The same regularizer had appeared independently in the inverse-problems literature as Tikhonov regularization, after Andrey Tikhonov's work on ill-posed problems in the 1940s and 1960s, where stabilizes the inversion of an ill-conditioned operator; the two traditions describe the same matrix .

The Bayesian reading — ridge as the posterior mean under a Gaussian prior on the coefficients — connects the method to the shrinkage estimators that James and Stein had shown in 1961 to dominate the sample mean in three or more dimensions, establishing that biased estimators can be uniformly better and that shrinkage toward a point is not a heuristic but a consequence of decision theory. The synthesis of ridge, subset selection, the lasso, and their Bayesian interpretations into a single account of shrinkage in regression was consolidated by Hastie, Tibshirani and Friedman [Hastie 2009] in chapter 3 of The Elements of Statistical Learning, where the singular-value shrinkage factors are given as the unifying description, and extended to the high-dimensional sparse regime by Hastie, Tibshirani and Wainwright [Hastie 2015].

Bibliography Master

@article{hoerl1970ridge,
  author  = {Hoerl, Arthur E. and Kennard, Robert W.},
  title   = {Ridge Regression: Biased Estimation for Nonorthogonal Problems},
  journal = {Technometrics},
  volume  = {12},
  number  = {1},
  pages   = {55--67},
  year    = {1970}
}

@article{hoerl1970ridgeapp,
  author  = {Hoerl, Arthur E. and Kennard, Robert W.},
  title   = {Ridge Regression: Applications to Nonorthogonal Problems},
  journal = {Technometrics},
  volume  = {12},
  number  = {1},
  pages   = {69--82},
  year    = {1970}
}

@book{hastie2009elements,
  author    = {Hastie, Trevor and Tibshirani, Robert and Friedman, Jerome},
  title     = {The Elements of Statistical Learning: Data Mining, Inference, and Prediction},
  edition   = {2},
  publisher = {Springer},
  year      = {2009},
  note      = {Chapter 3, linear methods for regression; §3.4 shrinkage methods}
}

@book{hastie2015sparsity,
  author    = {Hastie, Trevor and Tibshirani, Robert and Wainwright, Martin},
  title     = {Statistical Learning with Sparsity: The Lasso and Generalizations},
  publisher = {CRC Press},
  year      = {2015}
}

@article{james1961estimation,
  author  = {James, William and Stein, Charles},
  title   = {Estimation with Quadratic Loss},
  journal = {Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics and Probability},
  volume  = {1},
  pages   = {361--379},
  year    = {1961}
}

@book{tikhonov1977solutions,
  author    = {Tikhonov, Andrey N. and Arsenin, Vasiliy Y.},
  title     = {Solutions of Ill-Posed Problems},
  publisher = {Winston and Sons, Washington},
  year      = {1977}
}