Welcome to the penultimate lesson of our course. In the previous lesson, we introduced Ridge regression as a powerful tool to combat overfitting. You learned that by adding a penalty term, , to the loss function, we deliberately introduce a small amount of bias to shrink the model's weights, which in turn dramatically reduces the model's variance and improves its ability to generalize. We also saw the closed-form solution for Ridge regression:
Today, we will analyze this equation from a different angle. You will discover that the term provides a second, crucial benefit beyond just shrinking weights: it acts as a numerical stabilizer. By the end of this lesson, you will be able to analyze how adding this term directly improves the condition number of the matrix , making the optimization problem much easier to solve. This will connect our recent discussions on regularization with our earlier module on conditioning and numerical stability.
The Problem Revisited: Multicollinearity and Ill-Conditioning
Let's start by connecting a statistical problem to a mathematical one. In statistics, multicollinearity occurs when two or more features in a dataset are highly correlated. For example, in a biological dataset, the expression levels of two genes that are part of the same regulatory pathway might be highly correlated. In a housing dataset, a property's square footage and the number of bedrooms are also likely to be correlated.
When features are highly correlated, the matrix (also called the Gram matrix) becomes ill-conditioned or even singular.
- Intuition: If two features are nearly identical, the model has trouble deciding how to attribute the effect. It might find that a large positive weight on one feature and a large negative weight on the other cancel out to produce a good fit. This leads to extremely large, unstable coefficients that are sensitive to small changes in the training data.
- Mathematical Consequence: Correlated columns in mean the matrix is nearly singular. Its determinant is close to zero, and inverting it () is a numerically unstable operation. The inverse essentially "blows up," leading to the large, unstable coefficients we see.
The following video gives a great example of this problem and introduces the instability it causes.
This video from the channel ritvikmath explains why Ordinary Least Squares (OLS) can fail when features are correlated.
Watch the segment from this point. The speaker uses an example of predicting food spending from income and taxes—two highly correlated variables. Pay attention to the core idea: when explanatory variables are highly correlated, the variance of the estimated coefficients becomes "abnormally large," making the model unreliable.
This high variance and numerical instability are symptoms of an underlying ill-conditioned problem. As we saw in a previous lesson, an ill-conditioned matrix corresponds to a loss surface shaped like a narrow canyon, which is difficult for optimizers like gradient descent to navigate.

The Elegant Fix: How Stabilizes the Matrix
This is where the Ridge regression solution shines. The key is the modification to the matrix we need to invert: . Let's analyze what this addition does from an eigenvalue perspective.
Recall that is a symmetric, positive semi-definite matrix, meaning all its eigenvalues are non-negative (). If the matrix is ill-conditioned, at least one of its eigenvalues is very close to zero. If it's singular (perfect multicollinearity), at least one eigenvalue is exactly zero.
Now, consider the new matrix . Let's see how it acts on an eigenvector of . If is an eigenvector with eigenvalue , we have:
Applying the new matrix to gives:
This is a remarkable result. The matrix has the exact same eigenvectors as , but each of its eigenvalues has been shifted up by .
This simple addition of a scaled identity matrix is sometimes called "lifting the eigenvalues." Since , even if had an eigenvalue of 0, the smallest eigenvalue of the new matrix is now at least . This guarantees the matrix is invertible and protects the inversion from "blowing up."
The following resources provide a clear walkthrough of this crucial mechanism.
Ridge Regression is a Gaussian Prior
This short video from DataMListic gives a concise and direct explanation of the problem and the Ridge solution.
First, watch the section describing the problem from the beginning. It vividly describes how the inverse "blows up" when \mathbf{X}^T\mathbf{X} is nearly singular. Next, watch the explanation of the fix from this segment. The key insight is that adding \lambda\mathbf{I} "stabilizes the inverse" because the matrix can no longer be singular.
For a more detailed mathematical treatment, the following article is excellent.
Condition numbers | Personal blog of Boris Burkov
This article by Boris Burkov provides a rigorous yet clear explanation of how L2 regularization helps with ill-conditioning.
Read the section "L2-regularization from the condition numbers perspective". The text walks through the derivation we just discussed, showing precisely how regularization increments all the eigenvalues by \lambda, guaranteeing that the new smallest eigenvalue is at least \lambda.
Quantifying the Improvement: The Condition Number
We can now quantify exactly how much this stabilization helps. Recall that the condition number of a symmetric positive definite matrix is the ratio of its largest to smallest eigenvalue:
For an ill-conditioned matrix, is very close to 0, making enormous.
Now, let's look at the condition number of the regularized matrix, . Its eigenvalues are . Therefore, its condition number is:
Let's plug in some numbers. Suppose is very ill-conditioned, with and .
The original condition number is .
Now, we apply Ridge regression with a small regularization parameter, say .
The new condition number is .
The condition number has improved by over 100 times! By adding to both the numerator and the denominator, we push the ratio significantly closer to 1. This makes the problem numerically stable and far easier for an optimization algorithm to solve. The concept is also summarized neatly in this short extract.
[PDF] Ridge Regression - Emtiyaz Khan
This annotated lecture slide from Emtiyaz Khan gives a succinct summary of the concept.
Focus on the section "Ridge regression to fight ill-conditioning". It directly states the conclusion: "ridge regression improves the condition number of the Gram matrix."
The Geometric Picture
This mathematical improvement has a direct geometric interpretation. Adding the circular penalty bowl () to the elliptical MSE bowl () makes the overall loss surface "rounder" or more spherical.

An improved condition number means the ratio of the steepest curvature to the shallowest curvature is smaller. This reshaped landscape makes the job of gradient descent much easier, as the negative gradient now points more directly towards the new minimum.
Conclusion
In this lesson, you've uncovered a second, equally important role of Ridge regression. It is not just a statistical tool for managing the bias-variance tradeoff, but also a powerful numerical tool for ensuring model stability.
Here are the key takeaways:
- Problem: Multicollinearity (correlated features) in the data matrix leads to an ill-conditioned or singular matrix. This causes numerical instability and high variance in the model's coefficients.
- Mechanism: The Ridge penalty term is added to before inversion. This has the effect of "lifting" every eigenvalue of by .
- Result: This eigenvalue shift guarantees that the new matrix is invertible and dramatically reduces its condition number, .
- Benefit: A lower condition number means the problem is more numerically stable, and the loss surface is more uniform, which helps optimization algorithms like gradient descent converge faster and more reliably.
You've now seen how a single, elegant mathematical idea—L2 regularization—simultaneously addresses the statistical problem of overfitting and the numerical problem of ill-conditioning.
In our final lesson, we will contrast Ridge regression with its famous alternative, Lasso (L1) regression. You will see how a different penalty term leads to a different geometry and a different, but equally useful, outcome: model sparsity and automatic feature selection.