Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Ridge Tuning & GCV

A ridge fit is easy to calculate for a fixed penalty. The practical question is how much shrinkage improves prediction. Cross-validation and generalized cross-validation compare candidate penalties while accounting for the model’s flexibility.

Effective Degrees of Freedom

For a fixed response-independent design and penalty,

y^λ=Hλy,Hλ=X(X⊤X+λI)−1X⊤.\widehat y_\lambda=H_\lambda y,\qquad H_\lambda=X(X^\top X+\lambda I)^{-1}X^\top.

Under common error variance, the covariance definition of model complexity gives

df⁡(λ)=tr⁡(Hλ)=∑j=1rsj2sj2+λ.\boxed{\operatorname{df}(\lambda)=\operatorname{tr}(H_\lambda) =\sum_{j=1}^r\frac{s_j^2}{s_j^2+\lambda}.}

Each observed singular direction contributes between zero and one effective parameter. With all coefficients penalized, df decreases from rr as λ↓0\lambda\downarrow0 to zero as λ→∞\lambda\to\infty.

With an unpenalized intercept and centered predictor matrix ZcZ_c, the full smoother is

Hλ=J+Urdiag⁡(wj)Ur⊤,J=11⊤/n,H_\lambda=J+U_r\operatorname{diag}(w_j)U_r^\top,\qquad J=\mathbf1\mathbf1^\top/n,

so

df⁡(λ)=1+∑j=1rwj.\operatorname{df}(\lambda)=1+\sum_{j=1}^r w_j.

The extra one counts the fitted intercept. Here df tends to one as slopes are completely shrunk.

Exact LOO for a Fixed Ridge Procedure

For sum-scale ridge with the same numerical λ\lambda in every deleted fit,

Err⁡^LOO(λ)=1n∑i(yi−y^λ,i1−hλ,ii)2.\widehat{\operatorname{Err}}_{\mathrm{LOO}}(\lambda) =\frac1n\sum_i\left(\frac{y_i-\widehat y_{\lambda,i}}{1-h_{\lambda,ii}}\right)^2.

The identity also holds with a fixed penalty matrix that leaves the intercept unpenalized, provided the relevant deleted systems are invertible.

Why the OLS Shortcut Extends to Ridge

Set M=X⊤X+λPM=X^\top X+\lambda P, where P=IP=I for ordinary ridge or P=diag⁡(0,1,…,1)P=\operatorname{diag}(0,1,\ldots,1) with an unpenalized intercept. Deleting observation ii changes MM to M−xixi⊤M-x_ix_i^\top while leaving λP\lambda P fixed.

The same Sherman-Morrison calculation as in LOO & Generalized Cross-Validation yields

β^λ(−i)=β^λ−M−1xiei1−hii,hii=xi⊤M−1xi.\widehat\beta_\lambda^{(-i)} =\widehat\beta_\lambda-\frac{M^{-1}x_i e_i}{1-h_{ii}},\qquad h_{ii}=x_i^\top M^{-1}x_i.

Thus the deleted-fit residual is ei/(1−hii)e_i/(1-h_{ii}).

If software uses mean loss and keeps α\alpha fixed, the sum-scale penalty changes from nαn\alpha to (n−1)α(n-1)\alpha on deletion. The displayed full-fit shortcut assumes a fixed sum-scale penalty. Re-estimating predictor scales, selecting features, or retuning λ\lambda inside each deletion also changes the fitting procedure; use explicit folds to evaluate such a pipeline.

Generalized Cross-Validation

Replace individual leverages by their average:

GCV⁡(λ)=∥y−y^λ∥2/n[1−df⁡(λ)/n]2.\boxed{\operatorname{GCV}(\lambda) =\frac{\lVert y-\widehat y_\lambda\rVert^2/n} {[1-\operatorname{df}(\lambda)/n]^2}.}

Choose a candidate penalty with the smallest score and refit with that penalty. GCV approximates LOO by using a common leverage correction; it is not an additional exact deleted-data formula.

As λ\lambda increasesTypical consequence
Coefficient norm decreasesLess sensitivity to response noise.
Training RSS increases or stays constantThe fit moves away from its least-squares optimum.
Effective df decreasesThe GCV complexity correction becomes smaller.
Bias can increaseExcessive shrinkage can lose predictive signal.

The GCV score itself need not be monotone. Search a sufficiently broad grid, often spaced logarithmically. If the minimum lies at an edge, examine whether extending the range is appropriate. Include the OLS limit only when the denominator is nonzero and the numerical calculation is stable.

The minimum GCV score has been used for selection. It should not be treated as an unbiased final assessment of the chosen model. Use a held-out test set or outer CV when a separate assessment is needed.

Efficient Evaluation Across Penalties

For the all-penalized convention, precompute a compact SVD and c=Ur⊤yc=U_r^\top y. Write y⊥=(I−UrUr⊤)yy_\perp=(I-U_rU_r^\top)y. Then

y^λ=Urdiag⁡(wj)c,\widehat y_\lambda=U_r\operatorname{diag}(w_j)c,
RSS⁡(λ)=∥y⊥∥2+∑j=1r(1−wj)2cj2.\boxed{\operatorname{RSS}(\lambda) =\lVert y_\perp\rVert^2+\sum_{j=1}^r(1-w_j)^2c_j^2.}

Orthogonality makes the two residual components add without a cross term. After the SVD, both RSS and df require only sums over rr directions for each candidate penalty. For an unpenalized intercept, apply the same decomposition to ycy_c and ZcZ_c, then add one to df.

Residual Variance Is a Different Quantity

For a fixed smoother and true mean vector μ\mu,

E[∥(I−H)Y∥2∣X]=∥(I−H)μ∥2+σ2{n−2tr⁡(H)+tr⁡(H⊤H)}.E[\lVert(I-H)Y\rVert^2\mid X] =\lVert(I-H)\mu\rVert^2 +\sigma^2\{n-2\operatorname{tr}(H)+\operatorname{tr}(H^\top H)\}.

For correctly specified OLS, the bias term is zero and H2=HH^2=H, giving σ2(n−p)\sigma^2(n-p). For ridge, the bias term generally remains and H2≠HH^2\ne H. Therefore RSS⁡/[n−tr⁡(H)]\operatorname{RSS}/[n-\operatorname{tr}(H)] is not generally an unbiased variance estimator. GCV does not require a separate estimate of σ2\sigma^2.

Worked Spectral Comparison

Consider n=5n=5, two orthogonal design directions with s2=(9,1)s^2=(9,1), projected response coordinates c=(3,1)c=(3,1), and ∥y⊥∥2=2\lVert y_\perp\rVert^2=2. All coefficients are penalized in this example.

λ\lambdaShrinkage weightsdfRSSGCV
0(1,1)(1,1)2.02.001.1111
1(0.9,0.5)(0.9,0.5)1.42.340.9028
9(0.5,0.1)(0.5,0.1)0.65.061.3068

Among these three candidates, λ=1\lambda=1 has the lowest score. It allows a modest RSS increase while substantially reducing effective complexity. This discrete comparison does not claim that 1 minimizes GCV over every positive penalty.