Ridge solutions
Ridge adds a quadratic-penalty matrix to the least-squares normal system before solving for coefficients.
On this page 8 sections
- Overview
- Ridge regression trades some data fit for smaller coefficient magnitudes
- An intercept often remains unpenalized, but the objective decides
- The identity penalty changes diagonal entries only
- An identity penalty adds to diagonal entries, not every matrix entry
- Key takeaway
- Sources & further reading
- Concept connections
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:
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).
With , right side , and , an unpenalized first intercept uses mask . Add the penalty to get diagonal . Solve and , giving . The slope shrinks from 3; the intercept equation stays the same.
All coefficients penalized. Solve (G+λI)β=r. G=diag(3, 5), r=, λ=1. Give β.
Show answer and explanation
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.
Intercept first, unpenalized. Solve (G+λdiag(0,1))β=r. G=diag(2, 4), r=, λ=1. Give β.
Show answer and explanation
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.
G rows: (3,1); (1,3), r=, λ=1. Draft adds λ everywhere. Penalize both: solve (G+λI)β=r.
Show answer and explanation
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.
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]Jonathan Taylor, STATS305B Penalized regression ↗Jonathan Taylor, STATS305B Penalized regression · Article