Ridge Regularization (L2 Regularization) › Summation Notation
Machine Learning from ScratchAll chapters Ridge Regularization (L2 Regularization) › Summation NotationOne section · Sections in this chapter3 / 9 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
As for LASSO, we can write the Ridge regression objective function as a summation:
where:
- = actual (observed) value for observation
- = predicted value for observation
- = regularization parameter (non-negative; )
- = intercept term (not penalized in Ridge regression)
- = coefficient for feature (where )
- = value of feature for observation
- = number of observations (sample size)
- = number of features (predictors)
This notation should look familiar from the previous section on LASSO. Rather than the L1 penalty, we have the L2 penalty, which is the sum of the squared coefficients.
This is the squared L2 norm (also called the L2 norm squared) of the coefficient vector , where is the L2 norm itself.
Matrix Notation
However, because matrix computations are much faster than summation, we can also write the Ridge regression objective function in matrix notation:
where:
- = vector of target values (observed responses)
- = design matrix of features (each row is an observation, each column is a feature)
- = vector of coefficients (parameters to estimate)
- = L2 norm (Euclidean norm), defined as
- = squared L2 norm, defined as
Closed-Form Solution
Because we are not encountering issues of non-differentiability, we can find the closed-form solution for the Ridge regression objective function. Taking the derivative with respect to and setting it to zero:
This yields the Ridge estimator:
where:
- = Ridge regression coefficient estimates
- = transpose of the design matrix
- = matrix (sum of squares and cross-products of features)
- = regularization parameter
- = identity matrix (diagonal matrix with 1s on the diagonal and 0s elsewhere)
- = matrix inverse operation
The identity matrix is a square matrix with ones on the diagonal and zeros elsewhere. For example, the identity matrix of size 3 is:
Mathematical Properties
- Bias-Variance Tradeoff: As increases, bias increases but variance decreases
- Shrinkage: All coefficients are shrunk toward zero. In the special case of orthonormal features (where ), each coefficient is multiplied by the shrinkage factor , meaning
- Stability: The term ensures is always invertible, even when is singular (non-invertible)
- Regularization Path: As , Ridge approaches OLS (); as , all coefficients approach zero ()

This visualization illustrates the fundamental bias-variance tradeoff in Ridge regression. When λ is very small (left side), the model is close to OLS and may overfit the training data, resulting in low training error but high test error due to high variance. As λ increases, the training error rises because the model becomes more constrained (increased bias), but the test error initially decreases as variance is reduced. The optimal λ (green line) achieves the best balance, minimizing test error. Beyond this point, further increasing λ causes underfitting, where the model becomes too simple and both training and test errors increase due to excessive bias.
We skipped over the derivation of the closed-form solution for Ridge regression, but it is similar to the derivation for LASSO, but easier since we are not encountering issues of non-differentiability, making the math more straightforward.
Regularization Path
To better understand how Ridge regression affects multiple coefficients simultaneously, let's visualize the regularization path.how each coefficient changes as we increase λ.

This plot reveals a key characteristic of Ridge regression: as λ increases, all coefficients shrink smoothly and continuously toward zero, but do not reach exactly zero. This is fundamentally different from LASSO, where coefficients can be driven to exactly zero. The smooth shrinkage means Ridge maintains all features in the model, which can be advantageous when all features are believed to be relevant or when dealing with highly correlated features.