core28 min studyLesson 258 in Mathematics

Ridge regression and bias–variance tradeoffs

Analyze shrinkage in singular-vector coordinates and assess bias, variance, scaling, and validation separately.

On this page

What you’ll understand

  • Derive the ridge estimator for a stated penalty convention.
  • Calculate directional shrinkage, bias, and variance.
  • Explain why lower training error and lower prediction risk are different objectives.

A nearly dependent design can make ordinary least-squares coefficients unstable even when the fitted training responses look reasonable. Ridge regression deliberately changes the optimization problem by penalizing coefficient size. The change introduces bias but can reduce variability in fragile directions. Understanding that exchange is more useful than treating regularization as a default improvement: the appropriate penalty depends on coefficient scaling, the prediction target, the unknown signal, and how tuning is performed. A smaller coefficient vector is not automatically a more accurate one.

Specify the objective and the coordinates

Use the objective squared residual norm plus λ∥b∥2\lambda\|b\|^2, with λ positive. Its gradient gives the modified normal equations. The added multiple of identity makes the matrix positive definite even if the design is rank deficient, so the minimizer is unique. This convention uses an unnormalized residual sum; software minimizing an average loss may report a penalty parameter differing by a factor of n. Compare objectives before comparing numerical tuning parameters.

The penalty treats the chosen coefficient coordinates as meaningful. Rescaling a predictor changes the cost of using its coefficient and generally changes a ridge fit unless the penalty is transformed too. Centering and standardizing predictors are therefore modeling choices that should be learned from training data and carried into validation and deployment. Many implementations leave the intercept unpenalized. The formulas here penalize every displayed coordinate; an intercept exemption requires replacing identity by an appropriate penalty matrix or centering it out first.

β^λ=arg min⁡b{∥Y−Xb∥2+λ∥b∥2}=(XTX+λI)−1XTY\widehat\beta_\lambda=\operatorname*{arg\,min}_b\{\|Y-Xb\|^2+\lambda\|b\|^2\}=(X^{\mathsf T}X+\lambda I)^{-1}X^{\mathsf T}Y
The formula uses λ>0 and penalizes all displayed coefficients. No probability distribution is needed to define this unique optimization solution.↔ Scroll wide equations horizontally.

Shrinkage acts most strongly in weak directions

Write a compact singular-value decomposition X=Udiag⁡(dj)VTX=U\operatorname{diag}(d_j)V^{\mathsf T} with positive singular values. In the corresponding coefficient directions, ordinary least squares divides the response coordinate by dⱼ. Ridge replaces that multiplier with dj/(dj2+λ)d_j/(d_j^2+\lambda), shrinking the identifiable least-squares coordinate by dj2/(dj2+λ)d_j^2/(d_j^2+\lambda). Small singular directions are shrunk most heavily. Nullspace directions receive zero under this penalty convention, a chosen extrapolation rule rather than newly recovered information.

Under a correct mean model with spherical error covariance, that same multiplier makes the bias and variance transparent. If θⱼ is the true coefficient in a singular-vector direction, the expected estimate is the shrinkage factor times θⱼ. Its variance is σ2dj2/(dj2+λ)2\sigma^2d_j^2/(d_j^2+\lambda)^2. Squared bias and variance add to mean squared error in that direction. Reducing the variance cannot by itself establish improvement, because the squared bias also depends on the unknown signal.

Bias⁡(θ^j)=−λdj2+λθj,Var⁡(θ^j)=σ2dj2(dj2+λ)2\operatorname{Bias}(\widehat\theta_j)=-\frac{\lambda}{d_j^2+\lambda}\theta_j,\qquad \operatorname{Var}(\widehat\theta_j)=\frac{\sigma^2d_j^2}{(d_j^2+\lambda)^2}
For an identifiable singular direction, these moments assume E(Y)=Xβ and Cov(Y)=σ²I. Gaussianity is unnecessary, and the bias is relative to the true coefficient in that direction.↔ Scroll wide equations horizontally.

Tune for the question being evaluated

Unpenalized least squares already minimizes training residual sum of squares, so ridge cannot improve that particular score on the same fixed dataset. Its motivation is better risk on a specified future target or more stable interpretation under a justified penalty. Coefficient mean squared error and prediction error weight directions differently: predicting Xβ downweights weak singular directions, while extrapolating to new predictor rows can emphasize them. A statement about one risk does not automatically establish another.

Validation estimates performance without knowing the true coefficients, provided splits respect the deployment sampling structure. All preprocessing and penalty selection belong inside the training portion of each split; time dependence or grouped measurements may require structured rather than random splits. Reusing the final test set to choose λ makes it part of training. Ridge also cannot restore a missing conditional-mean assumption or identify causal effects from correlated predictors. Its uniqueness resolves an optimization ambiguity, not every scientific ambiguity in the data.

Shrink two singular directions by different amounts

Take X=diag⁡(1,2)X=\operatorname{diag}(1,2), observed y=(2,6)Ty=(2,6)^{\mathsf T}, and λ=1, penalizing both coefficients. Compute ridge and compare its objective with unpenalized least squares.

  1. The Gram matrix is diag⁡(1,4)\operatorname{diag}(1,4) and XTy=(2,12)TX^{\mathsf T}y=(2,12)^{\mathsf T}. Adding identity gives diag⁡(2,5)\operatorname{diag}(2,5), hence β^1=(1,12/5)T\widehat\beta_1=(1,12/5)^{\mathsf T}.

  2. The unpenalized coefficients are (2,3)T(2,3)^{\mathsf T}. Ridge multiplies them by 1/21/2 and 4/54/5 respectively, so the weaker singular direction receives stronger shrinkage.

  3. Ridge fitted values are (1,24/5)(1,24/5) and residuals are (1,6/5)(1,6/5). Its residual sum of squares is 61/2561/25 and penalty is 169/25169/25, giving objective 230/25=9.2230/25=9.2. The unpenalized fit has zero residual but penalty 22+32=132^2+3^2=13.

The result

Ridge improves the penalized objective while increasing the unpenalized training residual sum. This arithmetic says nothing yet about which estimate has lower future prediction risk.

Explore the model

Interactive lab

Interactive lab · matrix

Inspect unequal singular scales before regularizing

Pause and Reset; set a=0.25 and b=0. Predict singular values 1 and 0.25 and condition number 4. Compare with a fresh Reset at a=1 and b=0. The matrix lab shows geometry and singular values only; it does not apply a ridge penalty. Use the displayed scales in the formula d²/(d²+λ) with λ=0.25 to predict shrinkage 0.8 and 0.2 in the first setting.

Inspect unequal singular scales before regularizingThe selected matrix is A = [[a,b],[0,1]]. Playback interpolates geometry between the identity and A; readouts always describe A. Its determinant is a and its singular values come from AᵀA. Positive a makes every supported matrix invertible. This two-dimensional family is not a general eigensolver or a learned network. Current readings: Area scale · det A: 1.4; Singular values · σmax, σmin: 1.597, 0.876; Condition number · κ₂(A): 1.823. All parameters are adjustable with the labeled controls below.Matrix A with first row 1.4, 0.6 and second row zero, one; display interpolates between identity and A while final determinant remains 1.4.−4−2024−2−1012x · equal geometric scaleyA = [ 1.4 0.6 ; 0 1 ]Display blend: 0% · final values below
Interpolated geometryOriginal unit squareSelected final transform
Area scale · det A
1.4
Singular values · σmax, σmin
1.597, 0.876
Condition number · κ₂(A)
1.823
t = 0 s

The selected matrix is A = [[a,b],[0,1]]. Playback interpolates geometry between the identity and A; readouts always describe A. Its determinant is a and its singular values come from AᵀA. Positive a makes every supported matrix invertible. This two-dimensional family is not a general eigensolver or a learned network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forRidge depends on singular scales and a chosen penalty, not merely on whether a matrix inverse exists.

Check your understanding

With fixed λ>0 and this unnormalized ridge objective, which singular direction has the smaller shrinkage factor?

Try it yourself

In the scalar model Y=2β+εY=2\beta+\varepsilon, suppose β=3 and Var(ε)=4 with E(ε)=0. For λ=4 calculate the ridge bias, variance, and coefficient mean squared error. Compare with ordinary least squares.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

The ridge coefficient is 2Y/(4+λ). Compute its expectation and variance before adding squared bias.

Compare with the solution

Ridge is Y/4Y/4, so its expectation is 6/4=1.56/4=1.5 and its bias is −1.5-1.5. Its variance is 4/16=0.254/16=0.25, giving MSE 2.25+0.25=2.52.25+0.25=2.5. Ordinary least squares is Y/2Y/2, unbiased with variance and MSE 4/4=14/4=1. Here the chosen penalty hurts coefficient risk despite lowering variance; shrinkage is not a universal improvement.

Take it with you

  • A penalty convention and predictor scaling are part of the model.
  • Small singular directions receive stronger shrinkage and acquire bias.
  • Validation must assess the intended prediction target without leaking tuning decisions.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.