Ridge regression and bias–variance tradeoffs
Analyze shrinkage in singular-vector coordinates and assess bias, variance, scaling, and validation separately.
On this page
The question for today
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 , 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.
Shrinkage acts most strongly in weak directions
Write a compact singular-value decomposition with positive singular values. In the corresponding coefficient directions, ordinary least squares divides the response coordinate by dⱼ. Ridge replaces that multiplier with , shrinking the identifiable least-squares coordinate by . 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 . 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.
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.
Work it through
Shrink two singular directions by different amounts
Take , observed , and λ=1, penalizing both coefficients. Compute ridge and compare its objective with unpenalized least squares.
The Gram matrix is and . Adding identity gives , hence .
The unpenalized coefficients are . Ridge multiplies them by and respectively, so the weaker singular direction receives stronger shrinkage.
Ridge fitted values are and residuals are . Its residual sum of squares is and penalty is , giving objective . The unpenalized fit has zero residual but penalty .
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.
The living notebook
Explore the model
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.
- Area scale · det A
- 1.4
- Singular values · σmax, σmin
- 1.597, 0.876
- Condition number · κ₂(A)
- 1.823
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.
Pause & reason
Check your understanding
Your turn
Try it yourself
In the scalar model , 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 , so its expectation is and its bias is . Its variance is , giving MSE . Ordinary least squares is , unbiased with variance and MSE . Here the chosen penalty hurts coefficient risk despite lowering variance; shrinkage is not a universal improvement.
Keep the idea
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.