Skip to content
Glacius
OptimizationConcept reference

Ridge solutions

Ridge adds a quadratic-penalty matrix to the least-squares normal system before solving for coefficients.

On this page 8 sections
  1. Overview
  2. Ridge regression trades some data fit for smaller coefficient magnitudes
  3. An intercept often remains unpenalized, but the objective decides
  4. The identity penalty changes diagonal entries only
  5. An identity penalty adds to diagonal entries, not every matrix entry
  6. Key takeaway
  7. Sources & further reading
  8. Concept connections
Ridge with an unpenalized intercept: coefficients (2,3) become (2,1.5) when λ=2 for G=diag(4,2), r=(8,6). The intercept bar stays fixed; the slope bar halves. Bar lengths share one scale.Ridge with an unpenalized intercept: coefficients (2,3) become (2,1.5) when λ=2 for G=diag(4,2), r=(8,6). The intercept bar stays fixed; the slope bar halves. Bar lengths share one scale.
Figure 1Ridge with an unpenalized intercept: coefficients (2,3) become (2,1.5) when λ=2 for G=diag(4,2), r=(8,6). The intercept bar stays fixed; the slope bar halves. Bar lengths share one scale.
Link to this figure ↗Download SVGDownload PNG

01Ridge regression trades some data fit for smaller coefficient magnitudes#

Ridge regression trades some data fit for smaller coefficient magnitudes. This can stabilize a fit when feature columns are nearly redundant. The penalty changes the equations used to solve for coefficients, and its exact effect depends on which coefficients are penalized.

For a half-squared residual sum plus λ||β||²/2, λ≥0, penalizing every coefficient gives:

(XTX+λI)β=XTy(X^TX+\lambda I)\beta=X^Ty

Use a stated diagonal mask instead of I when some coefficients are unpenalized. We write G=XᵀX and r=Xᵀy.

If the intercept is first and unpenalized, add no penalty to its diagonal. With G=diag(4,2), r=(8,6) and λ=2, solve diag(4,4)β=r to get (2,1.5).

(4004)(β0β1)=(86)\begin{gathered}\begin{pmatrix}4&0\\0&4\end{pmatrix}\begin{pmatrix}\beta_0\\\beta_1\end{pmatrix}\\=\begin{pmatrix}8\\6\end{pmatrix}\end{gathered}

With G=XTX=diag(4,2)G=X^TX=\operatorname{diag}(4,2), right side (8,6)(8,6), and λ=2\lambda=2, an unpenalized first intercept uses mask diag(0,1)\operatorname{diag}(0,1). Add the penalty to get diagonal (4,4)(4,4). Solve 4β0=84\beta_0=8 and 4β1=64\beta_1=6, giving (2,1.5)(2,1.5). The slope shrinks from 3; the intercept equation stays the same.

Check your reasoning

All coefficients penalized. Solve (G+λI)β=r. G=diag(3, 5), r=(12,18)(12, 18), λ=1. Give β.

  1. A(3,4)(3, 4)
  2. B(3,3)(3, 3)
  3. C(4,3)(4, 3)
Show answer and explanation
(3,3)(3, 3)

Penalized diagonal (4, 6); solve both coordinates.

02An intercept often remains unpenalized, but the objective decides#

An intercept often remains unpenalized, but the objective decides. A mask diag(0,1) leaves the first coefficient alone while penalizing the second.

Apply the stated parameter order. An unpenalized intercept does not mean all coefficients escape the penalty.

Check your reasoning

Intercept first, unpenalized. Solve (G+λdiag(0,1))β=r. G=diag(2, 4), r=(8,15)(8, 15), λ=1. Give β.

  1. A(4,3)(4, 3)
  2. B(4,4)(4, 4)
  3. C(5,3)(5, 3)
Show answer and explanation
(4,3)(4, 3)

Solve diag(2,5)β=r.

03The identity penalty changes diagonal entries only#

The identity penalty changes diagonal entries only. Existing off-diagonal terms still couple coefficient equations.

Solve that coupled system as a system; dividing each right-hand side entry by its diagonal would ignore the coupling.

Check your reasoning

G rows: (3,1); (1,3), r=(9,6)(9,6), λ=1. Draft adds λ everywhere. Penalize both: solve (G+λI)β=r.

  1. A(2,0.5)(2, 0.5)
  2. B(3,1)(3, 1)
  3. C(2,1)(2, 1)
Show answer and explanation
(2,1)(2, 1)

Add λ to diagonals.

04An identity penalty adds to diagonal entries, not every matrix entry#

An identity penalty adds to diagonal entries, not every matrix entry. When off-diagonal terms are present, keep them and solve the coupled system. The penalty can make coefficients less sensitive, but its strength should be chosen using a valid training-and-validation procedure.

Key takeaway

Respect the coefficient order and intercept mask; add the penalty to the stated diagonal entries and solve the resulting system.

  • Solve a small penalized least-squares system with a stated treatment of the intercept.

Sources & further reading

  1. [1]
    Jonathan Taylor, STATS305B Penalized regressionJonathan Taylor, STATS305B Penalized regression · Article

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Ridge solutions.” Math behind ML. /learn/o-ridge