Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

L2 Regularization: Parameters and Bias-Variance

Recommended resources

The freely available resources this lesson will direct you to.

Hello! Welcome back to our study of linear regression.

In our last lesson, we formulated the Ridge regression model and derived its closed-form solution: . We established that by adding the term , we ensure the matrix is always invertible, providing a stable and unique solution even in the presence of multicollinearity.

Today, we will analyze the profound consequences of adding this penalty term. Our learning outcome is to explain the effect of L2 regularization on model parameters and the bias-variance trade-off. We will dissect how Ridge regression alters the coefficient estimates and then dive into a rigorous mathematical analysis of its impact on the model's bias and variance, which are the fundamental components of prediction error.

1. The Shrinkage Effect on Model Parameters

The most immediate effect of the L2 penalty is that it shrinks the regression coefficients towards zero. To build a clear intuition for this, let's consider the special case of an orthonormal design matrix, where (assuming features have been standardized to have mean 0 and standard deviation 1, which is common practice when using regularization).

In this scenario, the OLS solution simplifies to .
The Ridge solution becomes:

By substituting the OLS solution, we get a direct relationship:

This shows that the Ridge coefficients are a scaled-down version of the OLS coefficients. As increases, the scaling factor gets smaller, and the coefficients are shrunk more aggressively towards zero.

Geometric Interpretation

We can also visualize this effect. The OLS solution finds the coefficient vector that minimizes the Residual Sum of Squares (RSS). This can be visualized as finding the center of a set of elliptical contours representing the RSS value. The Ridge penalty, , imposes a constraint: it prefers solutions where the squared L2-norm of is small. This constraint region is a circle (in 2D) or a hypersphere centered at the origin.

The Ridge solution is found at the point of tangency between the RSS ellipse and the L2 constraint circle.

Geometric Interpretation of Ridge Regression (L2 Regularization)
This image illustrates the optimization process for Ridge regression. The red ellipses are the contour lines of the OLS cost function (RSS), with the OLS estimate \(\hat{\boldsymbol{\beta}}_{\text{OLS}}\) at the center. The teal circle is the L2 penalty constraint \(||\boldsymbol{\beta}||_2^2 \leq c\). The Ridge estimate, \(\hat{\boldsymbol{\beta}}_{\text{Ridge}}\), lies at the point where the smallest possible RSS ellipse touches the constraint circle. Notice how the parameter \(\beta_1\), which has a smaller impact on the cost function, is shrunk more significantly than \(\beta_2\).

This geometric view shows that Ridge doesn't just shrink all coefficients equally. It applies a "budget" to the sum of squared coefficients. To stay within this budget, it disproportionately shrinks the coefficients of less influential features.

2. Decomposing the Error: The Bias-Variance Trade-off

We've established that Ridge regression produces estimates that are different from . Since the OLS estimator is unbiased (under the classical assumptions), it follows that the Ridge estimator must be biased. A biased estimator is one whose expected value is not equal to the true parameter value.

So, why would we ever prefer a biased estimator? The answer lies in the bias-variance trade-off. The total expected error of a model can be decomposed into three parts:

  • Bias: The error from erroneous assumptions in the learning algorithm. High bias can cause an algorithm to miss relevant relations between features and target outputs (underfitting).
  • Variance: The error from sensitivity to small fluctuations in the training set. High variance can cause an algorithm to model the random noise in the training data (overfitting).
  • Irreducible Error: Noise inherent in the problem itself.

Ridge regression works by introducing a small amount of bias in exchange for a significant reduction in variance. To prove this rigorously, we will derive the expressions for the bias and variance of the Ridge estimator.

The following resource provides a detailed, step-by-step derivation that aligns with your interest in mathematical depth. We will work through its main results.

Bias-Variance Decomposition in Ridge Linear Regression

The document 'Bias-Variance Decomposition in Ridge Linear Regression' from Cornell University provides the formal derivations we need. It uses eigendecomposition to analyze the behavior of the bias and variance terms as a function of λ.

Please study sections 2 ('Bias') and 3 ('Variance'). The goal is not to memorize every step, but to understand the logic of the derivation and the final conclusions about how bias and variance change with λ. Pay attention to how the expectation is handled and how the eigendecomposition of XX^T is used to simplify the expressions.

The Bias of the Ridge Estimator

Let's summarize the derivation you just studied. We start by finding the expected value of the Ridge estimator, (using the notation from the paper, which is equivalent to our ), assuming the true model is with .

  1. Expectation of the Estimator:

    Since , we get:

  2. Bias Calculation:
    The bias of the estimator is . A clever algebraic trick shown in the paper reveals:

    Thus, the bias is:

    This is a crucial result. If , the bias is zero (recovering the unbiased OLS case). If , the estimator is biased, and the bias depends on the true parameters .

  3. Behavior of Bias:
    The paper goes on to show that the squared bias of the predictions, summed over the training data, is a monotonically increasing function of . It starts at 0 for and increases as we penalize the coefficients more heavily.

The Variance of the Ridge Estimator

Next, let's look at the variance. The variance measures how much the estimate would vary if we were to re-run the estimation on different training datasets (with different noise ).

  1. Deviation from the Mean:
    The derivation starts from the difference between the estimator and its mean:

    This shows that the variance comes entirely from the model's reaction to the noise in the data.

  2. Variance Calculation:
    Using matrix trace properties and the assumption that the noise terms are independent with unit variance (, where the paper assumes ), the variance of the predictions is derived. Using the eigendecomposition of , where are the diagonal entries of (eigenvalues), the variance simplifies to:

    (Note: The resource sets , but I've included it for generality).

  3. Behavior of Variance:
    From this final form, we can see that the variance is a monotonically decreasing function of .

    • When , the variance is , corresponding to the OLS variance.
    • As , each term , so the total variance approaches zero. This makes intuitive sense: a model that predicts zero regardless of the data has zero variance.
Test your understanding!

Based on the derivations, explain intuitively why the bias term depends on the true parameters , while the variance term depends on the noise variance .

Show answer
  • Bias is a measure of how far the average estimate is from the true value. The shrinkage effect systematically pulls the estimates away from the true values towards zero. The magnitude of this pull and the resulting error naturally depend on where the true values were to begin with. If is already close to zero, the bias will be small. If is large, the same shrinkage will introduce a larger bias.

  • Variance is a measure of the estimator's sensitivity to the random noise in the specific training sample. It measures the spread of estimates around their own average, not around the true value. This spread is caused by the estimator fitting to the random noise . Therefore, the variance formula fundamentally depends on the magnitude of that noise () and the structure of the data (), but not on the true parameters .

3. The Optimal Trade-off

We have established that as increases:

  • Bias² increases from 0.
  • Variance decreases towards 0.

Since the total error is the sum of these opposing forces, there must be a "sweet spot"—an optimal value of that minimizes the total error. This is the essence of the bias-variance trade-off.

Bias-Variance Trade-off in Ridge Regression
This graph visualizes the bias-variance trade-off. As the regularization parameter λ increases, the squared bias (blue line) rises, while the variance (red line) falls. The total test Mean Squared Error (black line), which is their sum, first decreases to a minimum and then rises again. The goal of tuning λ is to find this minimum point, which represents the best balance between bias and variance for optimal predictive performance.

This trade-off leads to a powerful and somewhat surprising theoretical result.

Ridge regression

The lecture notes on 'Ridge regression' by Patrick Breheny formalize this conclusion with an important existence theorem.

Please read the subsection 'Existence theorem' on page 19. It states a key result about the performance of Ridge regression compared to OLS.

As you just read, the theorem states: There always exists a value such that the Mean Squared Error (MSE) of the Ridge estimator is less than the MSE of the OLS estimator.

This guarantees that it is always possible to improve upon the OLS solution (in terms of expected prediction error) by introducing some bias through shrinkage. In practice, the optimal is an unknown hyperparameter that we must estimate, typically using a method like cross-validation.

Conclusion

In this lesson, we have moved from deriving the Ridge estimator to rigorously analyzing its behavior. We have seen that the L2 penalty has a profound impact on both the model parameters and its statistical properties.

Key Takeaways:

  • L2 regularization's primary effect on parameters is shrinkage: it pulls coefficient estimates towards zero, with a larger effect on less influential features.
  • This shrinkage introduces bias into the estimator, as the expected value of the Ridge coefficients is no longer equal to the true parameter values.
  • In return, shrinkage dramatically reduces the estimator's variance, making it less sensitive to the noise in the training data.
  • This dynamic creates the bias-variance trade-off. By accepting a small amount of bias, we can achieve a larger reduction in variance, leading to a model with a lower overall Mean Squared Error.
  • Theoretically, there is always a regularization strength that yields a better predictive model than OLS ().

Preview of the Next Module:
We have now completed our deep dive into linear regression, covering its formulation, analytical solutions (OLS and Ridge), and statistical properties. This foundational knowledge of linear models is essential. We will now pivot from regression to a new task: classification. In the next module, we will begin our study of Logistic Regression, exploring how the principles of linear models can be adapted to predict categorical outcomes.

Can't find a good explanation? Sign up and we'll make it for you

Sign up