Ridge Regression

Ridge regression fits a linear model by least squares with a penalty on the squared length of the coefficient vector. With standardized predictors and a centered response , it solves

where sets the strength of the penalty. The intercept is not penalized and equals . Setting the gradient to zero gives two equal closed forms:

The first form inverts a matrix. The second, the kernel form, inverts an matrix and is cheaper when . Both inverses exist for every , even when or columns are collinear. With the SVD of rank ,

Here are the singular values and , the singular vectors. The number is the least-squares coefficient along , and ridge keeps the fraction of it. The effective degrees of freedom falls from at toward as . As , ridge tends to OLS when has full column rank and to the minimum-norm solution otherwise.

Five descriptions give the same estimator:

  • Penalized least squares: the objective above.
  • Shifted spectrum: add to every eigenvalue of before inverting.
  • MAP estimate: with and prior , the posterior mode is ridge with .
  • Fake data: OLS on stacked over , with zero responses appended to .
  • Fake features: the minimum-norm solution of , whose first entries are ridge.

A generalized ridge (Tikhonov) penalty replaces by in the first closed form. Gradient descent on the ridge objective is weight decay:

Here is the learning rate. Each step multiplies the coefficients by before the data gradient acts. The factor comes from the penalty’s gradient . Cross-validation over a logarithmic grid chooses , with time-ordered folds for time series. Ridge is the usual choice when many correlated predictors each carry some signal. The lasso replaces it when the model must select a few predictors. Elastic net replaces it when correlated groups must be selected together.

Notation in CS 182

CS 182 writes the weights as and the number of features as , so its closed form reads . This note uses the regression notation and . Both use the unnormalized sum of squares. If the loss is averaged over the samples, the same estimator has penalty . Here always denotes a singular value, and without a subscript is the noise variance.

Not Taught in Lecture

Lecture did not define . It follows ESL §3.4.1, where it replaces the parameter count in model-selection criteria such as AIC.

Intuition

OLS divides each data coordinate by . A small singular value marks a direction along which the predictors barely vary, as with two nearly equal columns. Noise along that direction gets multiplied by the large factor , so the coefficients vary widely from sample to sample. Ridge replaces by . Directions with keep almost all of their coefficient, and directions with shrink toward zero. The fit gains some bias and loses much more variance (2.3.1. Bias-Variance Decomposition).

Hoerl and Kennard (1970) introduced the method and its name. A common reading of the name is the constant added along the diagonal of . The MAP view describes the same method in terms of a prior. Ridge assumes that each coefficient is small unless the data show otherwise. A larger means a tighter prior around zero.

The left panel tracks five ridge coefficients as grows. The right panel shows each shrink factor . Small singular directions shrink first, and no coefficient reaches exactly zero.

\usepackage{tikz}
\usetikzlibrary{animations, arrows.meta}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{grn}{HTML}{2F9E44}
\begin{tikzpicture}[font=\small, >={Stealth[length=2.2mm]}]
\draw[->] (0,-2.35) -- (7.75,-2.35) node[right] {$\log_{10}\lambda$};
\draw[->] (0,-2.35) -- (0,3.15) node[above] {$\beta_j$};
\draw[dashed] (0,0) -- (7.40,0);
\draw (0.00,-2.35) -- (0.00,-2.43) node[below] {\footnotesize $-2$};
\draw (1.85,-2.35) -- (1.85,-2.43) node[below] {\footnotesize $-1$};
\draw (3.70,-2.35) -- (3.70,-2.43) node[below] {\footnotesize $0$};
\draw (5.55,-2.35) -- (5.55,-2.43) node[below] {\footnotesize $1$};
\draw (7.40,-2.35) -- (7.40,-2.43) node[below] {\footnotesize $2$};
\draw (0,-1.20) -- (-0.08,-1.20) node[left] {\footnotesize $-1$};
\draw (0,1.20) -- (-0.08,1.20) node[left] {\footnotesize $1$};
\draw (0,2.40) -- (-0.08,2.40) node[left] {\footnotesize $2$};
\draw[hot, very thick] (0.00,2.57) -- (0.13,2.56) -- (0.27,2.55) -- (0.40,2.53) -- (0.54,2.51) -- (0.67,2.49) -- (0.81,2.47) -- (0.94,2.44) -- (1.08,2.41) -- (1.21,2.38) -- (1.35,2.34) -- (1.48,2.30) -- (1.61,2.26) -- (1.75,2.21) -- (1.88,2.15) -- (2.02,2.10) -- (2.15,2.03) -- (2.29,1.97) -- (2.42,1.90) -- (2.56,1.83) -- (2.69,1.76) -- (2.83,1.68) -- (2.96,1.60) -- (3.09,1.52) -- (3.23,1.44) -- (3.36,1.36) -- (3.50,1.27) -- (3.63,1.19) -- (3.77,1.10) -- (3.90,1.02) -- (4.04,0.94) -- (4.17,0.86) -- (4.31,0.78) -- (4.44,0.71) -- (4.57,0.63) -- (4.71,0.57) -- (4.84,0.50) -- (4.98,0.45) -- (5.11,0.39) -- (5.25,0.34) -- (5.38,0.30) -- (5.52,0.26) -- (5.65,0.23) -- (5.79,0.19) -- (5.92,0.17) -- (6.05,0.14) -- (6.19,0.12) -- (6.32,0.11) -- (6.46,0.09) -- (6.59,0.08) -- (6.73,0.07) -- (6.86,0.06) -- (7.00,0.05) -- (7.13,0.04) -- (7.27,0.03) -- (7.40,0.03);
\node[anchor=south west, inner sep=1pt] at (0.05,2.60) {\footnotesize $\beta_1$};
\draw[hot, dashed, very thick] (0.00,1.11) -- (0.13,1.12) -- (0.27,1.12) -- (0.40,1.13) -- (0.54,1.13) -- (0.67,1.14) -- (0.81,1.15) -- (0.94,1.16) -- (1.08,1.17) -- (1.21,1.18) -- (1.35,1.19) -- (1.48,1.20) -- (1.61,1.22) -- (1.75,1.22) -- (1.88,1.23) -- (2.02,1.24) -- (2.15,1.24) -- (2.29,1.24) -- (2.42,1.24) -- (2.56,1.23) -- (2.69,1.22) -- (2.83,1.20) -- (2.96,1.17) -- (3.09,1.14) -- (3.23,1.11) -- (3.36,1.07) -- (3.50,1.02) -- (3.63,0.97) -- (3.77,0.91) -- (3.90,0.86) -- (4.04,0.80) -- (4.17,0.74) -- (4.31,0.68) -- (4.44,0.62) -- (4.57,0.56) -- (4.71,0.50) -- (4.84,0.45) -- (4.98,0.40) -- (5.11,0.35) -- (5.25,0.31) -- (5.38,0.27) -- (5.52,0.24) -- (5.65,0.20) -- (5.79,0.18) -- (5.92,0.15) -- (6.05,0.13) -- (6.19,0.11) -- (6.32,0.10) -- (6.46,0.08) -- (6.59,0.07) -- (6.73,0.06) -- (6.86,0.05) -- (7.00,0.04) -- (7.13,0.04) -- (7.27,0.03) -- (7.40,0.03);
\node[anchor=south west, inner sep=1pt] at (0.05,1.14) {\footnotesize $\beta_2$};
\draw[cold, very thick] (0.00,-1.99) -- (0.13,-1.98) -- (0.27,-1.97) -- (0.40,-1.96) -- (0.54,-1.94) -- (0.67,-1.93) -- (0.81,-1.91) -- (0.94,-1.88) -- (1.08,-1.86) -- (1.21,-1.83) -- (1.35,-1.79) -- (1.48,-1.75) -- (1.61,-1.71) -- (1.75,-1.66) -- (1.88,-1.60) -- (2.02,-1.54) -- (2.15,-1.47) -- (2.29,-1.40) -- (2.42,-1.32) -- (2.56,-1.23) -- (2.69,-1.15) -- (2.83,-1.05) -- (2.96,-0.96) -- (3.09,-0.87) -- (3.23,-0.78) -- (3.36,-0.69) -- (3.50,-0.61) -- (3.63,-0.53) -- (3.77,-0.45) -- (3.90,-0.39) -- (4.04,-0.33) -- (4.17,-0.27) -- (4.31,-0.23) -- (4.44,-0.19) -- (4.57,-0.15) -- (4.71,-0.12) -- (4.84,-0.10) -- (4.98,-0.08) -- (5.11,-0.06) -- (5.25,-0.05) -- (5.38,-0.04) -- (5.52,-0.03) -- (5.65,-0.03) -- (5.79,-0.02) -- (5.92,-0.02) -- (6.05,-0.01) -- (6.19,-0.01) -- (6.32,-0.01) -- (6.46,-0.01) -- (6.59,-0.01) -- (6.73,-0.01) -- (6.86,-0.00) -- (7.00,-0.00) -- (7.13,-0.00) -- (7.27,-0.00) -- (7.40,-0.00);
\node[anchor=south west, inner sep=1pt] at (0.05,-1.96) {\footnotesize $\beta_3$};
\draw[cold, dashed, very thick] (0.00,1.52) -- (0.13,1.51) -- (0.27,1.50) -- (0.40,1.49) -- (0.54,1.48) -- (0.67,1.47) -- (0.81,1.45) -- (0.94,1.43) -- (1.08,1.41) -- (1.21,1.38) -- (1.35,1.36) -- (1.48,1.32) -- (1.61,1.29) -- (1.75,1.25) -- (1.88,1.20) -- (2.02,1.15) -- (2.15,1.10) -- (2.29,1.04) -- (2.42,0.98) -- (2.56,0.91) -- (2.69,0.85) -- (2.83,0.78) -- (2.96,0.71) -- (3.09,0.64) -- (3.23,0.57) -- (3.36,0.51) -- (3.50,0.45) -- (3.63,0.40) -- (3.77,0.35) -- (3.90,0.30) -- (4.04,0.26) -- (4.17,0.22) -- (4.31,0.19) -- (4.44,0.16) -- (4.57,0.14) -- (4.71,0.12) -- (4.84,0.10) -- (4.98,0.09) -- (5.11,0.07) -- (5.25,0.06) -- (5.38,0.05) -- (5.52,0.05) -- (5.65,0.04) -- (5.79,0.03) -- (5.92,0.03) -- (6.05,0.02) -- (6.19,0.02) -- (6.32,0.02) -- (6.46,0.01) -- (6.59,0.01) -- (6.73,0.01) -- (6.86,0.01) -- (7.00,0.01) -- (7.13,0.01) -- (7.27,0.01) -- (7.40,0.00);
\node[anchor=south west, inner sep=1pt] at (0.05,1.55) {\footnotesize $\beta_4$};
\draw[black, very thick] (0.00,-0.35) -- (0.13,-0.35) -- (0.27,-0.35) -- (0.40,-0.35) -- (0.54,-0.35) -- (0.67,-0.34) -- (0.81,-0.34) -- (0.94,-0.34) -- (1.08,-0.34) -- (1.21,-0.33) -- (1.35,-0.33) -- (1.48,-0.32) -- (1.61,-0.32) -- (1.75,-0.31) -- (1.88,-0.30) -- (2.02,-0.29) -- (2.15,-0.28) -- (2.29,-0.27) -- (2.42,-0.26) -- (2.56,-0.25) -- (2.69,-0.24) -- (2.83,-0.23) -- (2.96,-0.21) -- (3.09,-0.20) -- (3.23,-0.19) -- (3.36,-0.17) -- (3.50,-0.16) -- (3.63,-0.15) -- (3.77,-0.13) -- (3.90,-0.12) -- (4.04,-0.11) -- (4.17,-0.10) -- (4.31,-0.09) -- (4.44,-0.08) -- (4.57,-0.07) -- (4.71,-0.06) -- (4.84,-0.05) -- (4.98,-0.04) -- (5.11,-0.04) -- (5.25,-0.03) -- (5.38,-0.03) -- (5.52,-0.02) -- (5.65,-0.02) -- (5.79,-0.02) -- (5.92,-0.02) -- (6.05,-0.01) -- (6.19,-0.01) -- (6.32,-0.01) -- (6.46,-0.01) -- (6.59,-0.01) -- (6.73,-0.01) -- (6.86,-0.00) -- (7.00,-0.00) -- (7.13,-0.00) -- (7.27,-0.00) -- (7.40,-0.00);
\node[anchor=south west, inner sep=1pt] at (0.05,-0.32) {\footnotesize $\beta_5$};
\draw (9.00,-1.2) -- (14.20,-1.2);
\draw[dashed] (9.00,2.40) -- (14.20,2.40) node[right] {\footnotesize $1$};
\node[below] at (9.60,-1.2) {\footnotesize $2.07$};
\node[below] at (10.60,-1.2) {\footnotesize $1.44$};
\node[below] at (11.60,-1.2) {\footnotesize $0.91$};
\node[below] at (12.60,-1.2) {\footnotesize $0.43$};
\node[below] at (13.60,-1.2) {\footnotesize $0.15$};
\node[anchor=east] at (9.00,-1.48) {\footnotesize $\sigma_i^2$};
\node at (11.60,3.40) {shrink factor $\sigma_i^2 / (\sigma_i^2 + \lambda)$};
\node at (11.60,2.90) {\footnotesize one bar per singular direction $\mathbf v_i$};
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 2.4s = "false", 15s = "false", repeats}}}]
\draw[thick] (0.00,-2.35) -- (0.00,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.01$};
\filldraw[draw=black, fill=hot] (0.00,2.57) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (0.00,1.11) circle (2.4pt);
\filldraw[draw=black, fill=cold] (0.00,-1.99) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (0.00,1.52) circle (2.4pt);
\filldraw[draw=black, fill=black] (0.00,-0.35) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,2.383);
\node[below] at (9.60,2.383) {\footnotesize $1.00$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,2.375);
\node[below] at (10.60,2.375) {\footnotesize $0.99$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,2.361);
\node[below] at (11.60,2.361) {\footnotesize $0.99$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,2.318);
\node[below] at (12.60,2.318) {\footnotesize $0.98$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,2.175);
\node[below] at (13.60,2.175) {\footnotesize $0.94$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 4.89$};
\node[anchor=west] at (-0.9,-3.75) {Small $\lambda$: ridge is close to OLS. Every shrink factor is close to $1$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.4s = "true", 2.64s = "false", 15s = "false", repeats}}}]
\draw[thick] (0.16,-2.35) -- (0.16,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.0122$};
\filldraw[draw=black, fill=hot] (0.16,2.56) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (0.16,1.12) circle (2.4pt);
\filldraw[draw=black, fill=cold] (0.16,-1.98) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (0.16,1.51) circle (2.4pt);
\filldraw[draw=black, fill=black] (0.16,-0.35) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,2.379);
\node[below] at (9.60,2.379) {\footnotesize $0.99$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,2.370);
\node[below] at (10.60,2.370) {\footnotesize $0.99$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,2.352);
\node[below] at (11.60,2.352) {\footnotesize $0.99$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,2.300);
\node[below] at (12.60,2.300) {\footnotesize $0.97$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,2.129);
\node[below] at (13.60,2.129) {\footnotesize $0.92$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 4.87$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The coefficients and the factors start to shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.64s = "true", 2.88s = "false", 15s = "false", repeats}}}]
\draw[thick] (0.56,-2.35) -- (0.56,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.0202$};
\filldraw[draw=black, fill=hot] (0.56,2.51) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (0.56,1.14) circle (2.4pt);
\filldraw[draw=black, fill=cold] (0.56,-1.94) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (0.56,1.48) circle (2.4pt);
\filldraw[draw=black, fill=black] (0.56,-0.35) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,2.365);
\node[below] at (9.60,2.365) {\footnotesize $0.99$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,2.350);
\node[below] at (10.60,2.350) {\footnotesize $0.99$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,2.322);
\node[below] at (11.60,2.322) {\footnotesize $0.98$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,2.237);
\node[below] at (12.60,2.237) {\footnotesize $0.95$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,1.973);
\node[below] at (13.60,1.973) {\footnotesize $0.88$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 4.79$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The coefficients and the factors start to shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.88s = "true", 3.12s = "false", 15s = "false", repeats}}}]
\draw[thick] (1.09,-2.35) -- (1.09,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.0387$};
\filldraw[draw=black, fill=hot] (1.09,2.41) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (1.09,1.17) circle (2.4pt);
\filldraw[draw=black, fill=cold] (1.09,-1.85) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (1.09,1.41) circle (2.4pt);
\filldraw[draw=black, fill=black] (1.09,-0.34) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,2.334);
\node[below] at (9.60,2.334) {\footnotesize $0.98$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,2.306);
\node[below] at (10.60,2.306) {\footnotesize $0.97$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,2.253);
\node[below] at (11.60,2.253) {\footnotesize $0.96$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,2.100);
\node[below] at (12.60,2.100) {\footnotesize $0.92$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,1.661);
\node[below] at (13.60,1.661) {\footnotesize $0.79$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 4.63$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The coefficients and the factors start to shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.12s = "true", 3.36s = "false", 15s = "false", repeats}}}]
\draw[thick] (1.61,-2.35) -- (1.61,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.0743$};
\filldraw[draw=black, fill=hot] (1.61,2.26) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (1.61,1.21) circle (2.4pt);
\filldraw[draw=black, fill=cold] (1.61,-1.71) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (1.61,1.29) circle (2.4pt);
\filldraw[draw=black, fill=black] (1.61,-0.32) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,2.275);
\node[below] at (9.60,2.275) {\footnotesize $0.97$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,2.223);
\node[below] at (10.60,2.223) {\footnotesize $0.95$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,2.128);
\node[below] at (11.60,2.128) {\footnotesize $0.92$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,1.866);
\node[below] at (12.60,1.866) {\footnotesize $0.85$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,1.207);
\node[below] at (13.60,1.207) {\footnotesize $0.67$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 4.36$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The coefficients and the factors start to shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.36s = "true", 3.6s = "false", 15s = "false", repeats}}}]
\draw[thick] (2.01,-2.35) -- (2.01,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.123$};
\filldraw[draw=black, fill=hot] (2.01,2.10) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (2.01,1.24) circle (2.4pt);
\filldraw[draw=black, fill=cold] (2.01,-1.54) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (2.01,1.15) circle (2.4pt);
\filldraw[draw=black, fill=black] (2.01,-0.29) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,2.199);
\node[below] at (9.60,2.199) {\footnotesize $0.94$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,2.117);
\node[below] at (10.60,2.117) {\footnotesize $0.92$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,1.972);
\node[below] at (11.60,1.972) {\footnotesize $0.88$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,1.596);
\node[below] at (12.60,1.596) {\footnotesize $0.78$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,0.780);
\node[below] at (13.60,0.780) {\footnotesize $0.55$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 4.07$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. The coefficients and the factors start to shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.6s = "true", 6.4s = "false", 15s = "false", repeats}}}]
\draw[thick] (2.18,-2.35) -- (2.18,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.15$};
\filldraw[draw=black, fill=hot] (2.18,2.02) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (2.18,1.24) circle (2.4pt);
\filldraw[draw=black, fill=cold] (2.18,-1.46) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (2.18,1.09) circle (2.4pt);
\filldraw[draw=black, fill=black] (2.18,-0.28) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,2.157);
\node[below] at (9.60,2.157) {\footnotesize $0.93$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,2.060);
\node[below] at (10.60,2.060) {\footnotesize $0.91$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,1.891);
\node[below] at (11.60,1.891) {\footnotesize $0.86$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,1.463);
\node[below] at (12.60,1.463) {\footnotesize $0.74$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,0.600);
\node[below] at (13.60,0.600) {\footnotesize $0.50$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 3.94$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda = \sigma_5^2 = 0.15$: direction $5$ is halved. Direction $1$ keeps $93\%$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.4s = "true", 6.64s = "false", 15s = "false", repeats}}}]
\draw[thick] (2.33,-2.35) -- (2.33,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.182$};
\filldraw[draw=black, fill=hot] (2.33,1.95) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (2.33,1.24) circle (2.4pt);
\filldraw[draw=black, fill=cold] (2.33,-1.37) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (2.33,1.02) circle (2.4pt);
\filldraw[draw=black, fill=black] (2.33,-0.27) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,2.109);
\node[below] at (9.60,2.109) {\footnotesize $0.92$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,1.995);
\node[below] at (10.60,1.995) {\footnotesize $0.89$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,1.800);
\node[below] at (11.60,1.800) {\footnotesize $0.83$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,1.323);
\node[below] at (12.60,1.323) {\footnotesize $0.70$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,0.425);
\node[below] at (13.60,0.425) {\footnotesize $0.45$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 3.79$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. Direction $5$ shrinks fastest.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.64s = "true", 6.88s = "false", 15s = "false", repeats}}}]
\draw[thick] (2.72,-2.35) -- (2.72,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.296$};
\filldraw[draw=black, fill=hot] (2.72,1.74) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (2.72,1.21) circle (2.4pt);
\filldraw[draw=black, fill=cold] (2.72,-1.12) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (2.72,0.83) circle (2.4pt);
\filldraw[draw=black, fill=black] (2.72,-0.24) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,1.950);
\node[below] at (9.60,1.950) {\footnotesize $0.87$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,1.785);
\node[below] at (10.60,1.785) {\footnotesize $0.83$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,1.516);
\node[below] at (11.60,1.516) {\footnotesize $0.75$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,0.924);
\node[below] at (12.60,0.924) {\footnotesize $0.59$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,0.010);
\node[below] at (13.60,0.010) {\footnotesize $0.34$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 3.38$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. Direction $5$ shrinks fastest.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.88s = "true", 7.12s = "false", 15s = "false", repeats}}}]
\draw[thick] (3.23,-2.35) -- (3.23,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 0.558$};
\filldraw[draw=black, fill=hot] (3.23,1.44) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (3.23,1.11) circle (2.4pt);
\filldraw[draw=black, fill=cold] (3.23,-0.78) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (3.23,0.57) circle (2.4pt);
\filldraw[draw=black, fill=black] (3.23,-0.19) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,1.637);
\node[below] at (9.60,1.637) {\footnotesize $0.79$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,1.395);
\node[below] at (10.60,1.395) {\footnotesize $0.72$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,1.033);
\node[below] at (11.60,1.033) {\footnotesize $0.62$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,0.360);
\node[below] at (12.60,0.360) {\footnotesize $0.43$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,-0.437);
\node[below] at (13.60,-0.437) {\footnotesize $0.21$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 2.77$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. Direction $5$ shrinks fastest.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.12s = "true", 7.36s = "false", 15s = "false", repeats}}}]
\draw[thick] (3.74,-2.35) -- (3.74,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 1.05$};
\filldraw[draw=black, fill=hot] (3.74,1.12) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (3.74,0.93) circle (2.4pt);
\filldraw[draw=black, fill=cold] (3.74,-0.47) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (3.74,0.36) circle (2.4pt);
\filldraw[draw=black, fill=black] (3.74,-0.13) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,1.190);
\node[below] at (9.60,1.190) {\footnotesize $0.66$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,0.882);
\node[below] at (10.60,0.882) {\footnotesize $0.58$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,0.472);
\node[below] at (11.60,0.472) {\footnotesize $0.46$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,-0.160);
\node[below] at (12.60,-0.160) {\footnotesize $0.29$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,-0.750);
\node[above] at (13.60,-0.750) {\footnotesize $0.13$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 2.12$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. Direction $5$ shrinks fastest.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.36s = "true", 7.6s = "false", 15s = "false", repeats}}}]
\draw[thick] (4.13,-2.35) -- (4.13,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 1.71$};
\filldraw[draw=black, fill=hot] (4.13,0.88) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (4.13,0.76) circle (2.4pt);
\filldraw[draw=black, fill=cold] (4.13,-0.29) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (4.13,0.23) circle (2.4pt);
\filldraw[draw=black, fill=black] (4.13,-0.10) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,0.775);
\node[below] at (9.60,0.775) {\footnotesize $0.55$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,0.447);
\node[below] at (10.60,0.447) {\footnotesize $0.46$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,0.052);
\node[below] at (11.60,0.052) {\footnotesize $0.35$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,-0.480);
\node[below] at (12.60,-0.480) {\footnotesize $0.20$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,-0.909);
\node[above] at (13.60,-0.909) {\footnotesize $0.08$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 1.63$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. Direction $5$ shrinks fastest.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.6s = "true", 10.4s = "false", 15s = "false", repeats}}}]
\draw[thick] (4.29,-2.35) -- (4.29,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 2.07$};
\filldraw[draw=black, fill=hot] (4.29,0.79) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (4.29,0.69) circle (2.4pt);
\filldraw[draw=black, fill=cold] (4.29,-0.23) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (4.29,0.20) circle (2.4pt);
\filldraw[draw=black, fill=black] (4.29,-0.09) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,0.600);
\node[below] at (9.60,0.600) {\footnotesize $0.50$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,0.275);
\node[below] at (10.60,0.275) {\footnotesize $0.41$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,-0.102);
\node[below] at (11.60,-0.102) {\footnotesize $0.31$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,-0.586);
\node[below] at (12.60,-0.586) {\footnotesize $0.17$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,-0.957);
\node[above] at (13.60,-0.957) {\footnotesize $0.07$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 1.45$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda = \sigma_1^2 = 2.07$: direction $1$ is halved. Direction $5$ keeps $7\%$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 10.4s = "true", 10.64s = "false", 15s = "false", repeats}}}]
\draw[thick] (4.52,-2.35) -- (4.52,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 2.76$};
\filldraw[draw=black, fill=hot] (4.52,0.66) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (4.52,0.58) circle (2.4pt);
\filldraw[draw=black, fill=cold] (4.52,-0.17) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (4.52,0.15) circle (2.4pt);
\filldraw[draw=black, fill=black] (4.52,-0.07) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,0.343);
\node[below] at (9.60,0.343) {\footnotesize $0.43$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,0.033);
\node[below] at (10.60,0.033) {\footnotesize $0.34$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,-0.308);
\node[below] at (11.60,-0.308) {\footnotesize $0.25$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,-0.719);
\node[above] at (12.60,-0.719) {\footnotesize $0.13$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,-1.015);
\node[above] at (13.60,-1.015) {\footnotesize $0.05$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 1.20$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. Every coefficient moves toward $0$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 10.64s = "true", 10.88s = "false", 15s = "false", repeats}}}]
\draw[thick] (5.09,-2.35) -- (5.09,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 5.66$};
\filldraw[draw=black, fill=hot] (5.09,0.40) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (5.09,0.36) circle (2.4pt);
\filldraw[draw=black, fill=cold] (5.09,-0.07) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (5.09,0.08) circle (2.4pt);
\filldraw[draw=black, fill=black] (5.09,-0.04) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,-0.235);
\node[below] at (9.60,-0.235) {\footnotesize $0.27$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,-0.471);
\node[below] at (10.60,-0.471) {\footnotesize $0.20$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,-0.701);
\node[above] at (11.60,-0.701) {\footnotesize $0.14$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,-0.948);
\node[above] at (12.60,-0.948) {\footnotesize $0.07$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,-1.107);
\node[above] at (13.60,-1.107) {\footnotesize $0.03$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 0.70$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. Every coefficient moves toward $0$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 10.88s = "true", 11.12s = "false", 15s = "false", repeats}}}]
\draw[thick] (5.84,-2.35) -- (5.84,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 14.4$};
\filldraw[draw=black, fill=hot] (5.84,0.18) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (5.84,0.17) circle (2.4pt);
\filldraw[draw=black, fill=cold] (5.84,-0.02) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (5.84,0.03) circle (2.4pt);
\filldraw[draw=black, fill=black] (5.84,-0.02) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,-0.747);
\node[above] at (9.60,-0.747) {\footnotesize $0.13$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,-0.873);
\node[above] at (10.60,-0.873) {\footnotesize $0.09$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,-0.986);
\node[above] at (11.60,-0.986) {\footnotesize $0.06$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,-1.096);
\node[above] at (12.60,-1.096) {\footnotesize $0.03$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,-1.163);
\node[above] at (13.60,-1.163) {\footnotesize $0.01$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 0.32$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. Every coefficient moves toward $0$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.12s = "true", 11.36s = "false", 15s = "false", repeats}}}]
\draw[thick] (6.59,-2.35) -- (6.59,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 36.6$};
\filldraw[draw=black, fill=hot] (6.59,0.08) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (6.59,0.07) circle (2.4pt);
\filldraw[draw=black, fill=cold] (6.59,-0.01) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (6.59,0.01) circle (2.4pt);
\filldraw[draw=black, fill=black] (6.59,-0.01) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,-1.007);
\node[above] at (9.60,-1.007) {\footnotesize $0.05$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,-1.064);
\node[above] at (10.60,-1.064) {\footnotesize $0.04$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,-1.113);
\node[above] at (11.60,-1.113) {\footnotesize $0.02$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,-1.159);
\node[above] at (12.60,-1.159) {\footnotesize $0.01$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,-1.185);
\node[above] at (13.60,-1.185) {\footnotesize $0.004$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 0.13$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. Every coefficient moves toward $0$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.36s = "true", 11.6s = "false", 15s = "false", repeats}}}]
\draw[thick] (7.17,-2.35) -- (7.17,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 75$};
\filldraw[draw=black, fill=hot] (7.17,0.04) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (7.17,0.04) circle (2.4pt);
\filldraw[draw=black, fill=cold] (7.17,-0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (7.17,0.01) circle (2.4pt);
\filldraw[draw=black, fill=black] (7.17,-0.00) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,-1.103);
\node[above] at (9.60,-1.103) {\footnotesize $0.03$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,-1.132);
\node[above] at (10.60,-1.132) {\footnotesize $0.02$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,-1.157);
\node[above] at (11.60,-1.157) {\footnotesize $0.01$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,-1.180);
\node[above] at (12.60,-1.180) {\footnotesize $0.006$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,-1.193);
\node[above] at (13.60,-1.193) {\footnotesize $0.002$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 0.07$};
\node[anchor=west] at (-0.9,-3.75) {$\lambda$ grows. Every coefficient moves toward $0$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11.6s = "true", 15s = "true", repeats}}}]
\draw[thick] (7.40,-2.35) -- (7.40,3.05);
\node[anchor=east] at (7.40,3.47) {$\lambda = 100$};
\filldraw[draw=black, fill=hot] (7.40,0.03) circle (2.4pt);
\filldraw[draw=hot, thick, fill=white] (7.40,0.03) circle (2.4pt);
\filldraw[draw=black, fill=cold] (7.40,-0.00) circle (2.4pt);
\filldraw[draw=cold, thick, fill=white] (7.40,0.00) circle (2.4pt);
\filldraw[draw=black, fill=black] (7.40,-0.00) circle (2.4pt);
\filldraw[draw=black, fill=grn] (9.29,-1.2) rectangle (9.91,-1.127);
\node[above] at (9.60,-1.127) {\footnotesize $0.02$};
\filldraw[draw=black, fill=grn] (10.29,-1.2) rectangle (10.91,-1.149);
\node[above] at (10.60,-1.149) {\footnotesize $0.01$};
\filldraw[draw=black, fill=grn] (11.29,-1.2) rectangle (11.91,-1.168);
\node[above] at (11.60,-1.168) {\footnotesize $0.009$};
\filldraw[draw=black, fill=grn] (12.29,-1.2) rectangle (12.91,-1.185);
\node[above] at (12.60,-1.185) {\footnotesize $0.004$};
\filldraw[draw=black, fill=grn] (13.29,-1.2) rectangle (13.91,-1.195);
\node[above] at (13.60,-1.195) {\footnotesize $0.001$};
\node[anchor=west] at (9.00,-2.45) {effective df $= \sum_i$ factor $= 0.05$};
\node[anchor=west] at (-0.9,-3.75) {Small singular directions shrink first. No coefficient reaches exactly $0$.};
\end{scope}
\node[anchor=west] at (-0.9,-4.3) {\footnotesize red: $\beta_1, \beta_2$ (correlation $0.85$), \ blue: $\beta_3, \beta_4$ (correlation $0.5$), \ black: $\beta_5$, \ predictors centered, unit length};
\end{tikzpicture}
\end{document}

Properties

(Bias and Variance per Direction) Along each singular direction, ridge adds a bias that grows with and removes variance that OLS cannot avoid.

Not Taught in Lecture

These formulas follow Hoerl and Kennard (1970) and ESL §3.4.1. Lecture stated the trade-off without them.

Assume full column rank and write for the true coefficient along . Ridge estimates with bias and variance . Its mean squared error along this direction is

which equals the OLS value at . Its derivative has the sign of . Each direction therefore improves on OLS for every up to , where its error is smallest. Any between and lowers the total error below OLS. The best value for one direction matches the MAP value when .

(Bounded Noise Gain) Ridge never multiplies the data along any direction by more than .

OLS multiplies by , which has no upper bound as . Ridge uses . Since , this gain is at most , reached at . A near-duplicate predictor therefore cannot make the coefficients grow without bound. The condition number of the matrix to invert also drops, from to . A smaller condition number makes the solve less sensitive to rounding and makes gradient descent converge faster. Truncated SVD, or principal components regression, keeps directions above a cutoff whole and drops the rest. Ridge shrinks every direction by a smooth fraction.

(Early Stopping Acts Like Ridge) Plain gradient descent from zero, stopped after steps, filters the singular directions much as ridge with does.

Gradient descent with step on , started at , keeps the fraction

of the least-squares coefficient along . Directions with are nearly fit, and directions with have barely moved. Ridge with makes the same split, so stopping earlier acts like a larger . The two filters have different shapes. For , the bounds hold. Gradient descent therefore approaches exponentially fast on strong directions, while ridge approaches only like . Gradient descent can also overshoot. If , then at every odd , while the ridge fraction always stays below . In practice, early stopping saves checkpoints and keeps the one with the best validation error.

(Weight Decay With Adam) The penalty and the shrinkage step agree for plain gradient descent and disagree for adaptive optimizers.

Adam divides each gradient coordinate by a running scale of its past gradients. A penalty gradient added to the loss gets divided too, so coordinates with large gradients decay less. AdamW (Loshchilov and Hutter, 2019) applies the shrinkage as a separate step, outside the moment estimates. Its rate sits in the factor without a , so matches the penalty here under plain gradient descent. PyTorch’s weight_decay argument for SGD follows the same convention. Neural-network losses are usually averaged over the samples, which divides the matching by .

(Fast Cross-Validation) Ridge has an exact formula for leave-one-out cross-validation, so one SVD gives the whole error curve.

Not Taught in Lecture

This shortcut is from Golub, Heath and Wahba (1979) and ESL §7.10. Lecture chose with held-out data.

Let be the ridge hat matrix, so and . The leave-one-out error needs no refitting:

Generalized cross-validation (GCV) replaces each by the average . One SVD of gives and the diagonal of for every on the grid. The identity holds for a fixed design, including one with an unpenalized intercept column. It assumes exchangeable rows, so a time series still needs time-ordered folds.

Derivation

Expanding the objective gives . Its gradient is . Its Hessian is positive definite for , so the unique minimizer solves

For the kernel form, start from the identity . Multiply on the left by and on the right by :

For the SVD form, substitute with square orthogonal and . Then , and

The middle matrix has entries on its diagonal, which gives the sum in the callout. For the MAP view, the negative log posterior is, up to constants,

Multiplying by gives the ridge objective with . For the fake-data view, the stacked residual has squared length , which is the ridge objective.

Examples

(Easy) Two Uncorrelated Predictors

A bakery models daily croissant sales over days. Its two standardized predictors, temperature and a weekend indicator, happen to be uncorrelated, so . OLS gives croissants per standard deviation.

(Medium) Today's and Yesterday's Temperature

A utility predicts daily electricity demand from today’s and yesterday’s standardized temperature over days. The two predictors have correlation , so

(Medium) More Biomarkers Than Patients

A pilot study has patients and biomarkers. Take the columns as given and :

(Hard) Stopping Early Versus Adding a Penalty

An engineer fits a linear model by gradient descent on , from with step . The squared singular values of are , and . She stops after steps.

See Also