Introduction
Welcome back! In our previous lessons, we established two key methods for deriving point estimates from a posterior distribution:
- Minimum Mean Square Error (MMSE): Minimizing the average squared error leads to choosing the mean of the posterior.
- Maximum A Posteriori (MAP): Seeking the most probable parameter value leads to choosing the mode of the posterior.
We also saw that the MAP objective can be expressed as:
This formula—log-likelihood plus log-prior—might seem familiar if you've encountered regularization in machine learning. Today, we will make that connection explicit and achieve our learning outcome: to explain the relationship between MAP, MLE, and L2 regularization.
We will demonstrate that L2 regularization (also known as Ridge Regression) is not just an ad-hoc trick to prevent overfitting; it is the natural consequence of performing MAP estimation with a specific, and very common, prior belief about our model's parameters. This lesson will bridge the gap between the probabilistic Bayesian perspective and the optimization-focused frequentist/machine learning perspective on model fitting.
1. From Likelihood to Regularization: A Conceptual Overview
Before diving into the derivation, let's build the high-level intuition. We'll start by revisiting linear regression, the problem of overfitting, and how regularization is introduced as a solution. Then, we'll see how a Bayesian viewpoint provides a principled origin for this technique.
Bayesian Linear Regression : Data Science Concepts
This video by ritvikmath provides an excellent conceptual path from Ordinary Least Squares (OLS) regression to the Bayesian interpretation of regularization.
Please watch the video from 00:50 to 07:59. As you watch, focus on these key points: (00:50 - 04:50): The review of the linear regression model, its assumptions, and the introduction of Lasso (L1) and Ridge (L2) regularization as a way to control model complexity and prevent high-variance solutions. (04:50 - 07:59): The introduction of the Bayesian framework, where the goal shifts to maximizing the posterior probability, p(eta | y). Note how Bayes' theorem decomposes this posterior into the likelihood and the prior.
The video sets the stage perfectly. We have two seemingly different approaches to fitting a linear model:
- Regularized Least Squares: Minimize the sum of squared errors plus a penalty term on the size of the coefficients ().
- MAP Estimation: Maximize the posterior probability, which is proportional to the likelihood of the data times a prior probability on the coefficients.
Our goal now is to prove that these two approaches are, in fact, mathematically identical.
2. The Mathematical Equivalence of MAP and L2 Regularization
Let's begin the formal derivation. Your background in mechanical engineering involves modeling physical systems with equations; here, we are doing the same for a statistical system. We will build the model piece by piece, starting with the likelihood (the "physics" of the data-generating process) and then adding the prior (our "engineering assumptions" about the parameters).
Step 1: The Likelihood (Connection to MLE and Least Squares)
We begin with the standard linear model:
where is the vector of observations, is the design matrix, is the vector of coefficients, and is the error term. We assume the errors are independent and identically distributed, following a zero-mean Gaussian distribution: .
This assumption implies that the likelihood of observing given the parameters is also Gaussian:
The probability density function is:
To find the Maximum Likelihood Estimate (MLE), we maximize this function (or its log) with respect to .
Dropping the constant terms and the negative sign (which turns the argmax into an argmin), we get:
This is exactly the Ordinary Least Squares (OLS) objective function. Thus, OLS is equivalent to finding the MLE for a linear model with Gaussian noise.
The following resource provides a detailed derivation of this fact in the context of polynomial regression.
MATH 156 Machine Learning Lecture Note
This section from Hanbaek Lyu's lecture notes on Machine Learning rigorously shows how maximizing the likelihood of a model with Gaussian noise leads directly to the least squares cost function.
Please read Section 2.3, 'Polynomial Regression by Maximum Likelihood' (pages 8-10). Follow the derivation from Equation (23) to Equation (29). This shows how maximizing the log-likelihood function is equivalent to minimizing the squared error term.
Step 2: Adding the Prior
Now, let's move from MLE to MAP by introducing a prior on the weights . A common and sensible belief is that simpler models are better, which often translates to a preference for smaller coefficient values. A mathematically convenient way to express this is with a zero-mean Gaussian prior on each coefficient:
Assuming the coefficients are independent, the prior for the entire vector is:
Here, is a hyperparameter that controls the width of our prior. A small means we have a strong prior belief that the weights should be very close to zero. A large represents a weak, or "uninformative," prior.
Step 3: Deriving the MAP Estimate
The MAP estimate maximizes the log-posterior, which is the sum of the log-likelihood and the log-prior:
Substituting the expressions we found:
where and are constants with respect to . Dropping these constants and flipping the argmax to an argmin by negating the expression, we get:
We can multiply this objective by a positive constant, , without changing the location of the minimum:
Step 4: The Final Connection
Look closely at this final expression. It is precisely the objective function for Ridge Regression (L2 Regularization):
We have just proven that they are the same problem, where the regularization parameter is given by the ratio of the variances:
This entire derivation is laid out very clearly in the following resources.
MATH 156 Machine Learning Lecture Note
Let's return to the lecture notes, which formalize the Bayesian approach to regression and explicitly derive the MAP estimate, showing its equivalence to the L2-regularized problem.
Please read Section 2.4, 'Bayesian Polynomial Regression' (page 11). This section is the core of our lesson. Follow the derivation from the posterior definition in Equation (37) to the final MAP objective in Equation (43). This directly shows that the MAP estimate minimizes a function identical to the L2-regularized least squares objective.
Bayesian Linear Regression : Data Science Concepts
For a more visual and narrated walkthrough of the same derivation, we can watch the second half of the ritvikmath video.
Please watch from 07:59 to 14:04. This segment works through the exact steps we just took: Deriving the likelihood term from the Gaussian noise assumption. Introducing the Gaussian prior on the weights. Combining them to form the MAP objective and showing it is equivalent to the Ridge Regression cost function.
3. Visualizing and Interpreting the Relationship
The equivalence provides a profound intuition about regularization.
- Strong Prior (small ): If we are very confident that the weights should be small, our prior distribution is narrow. This leads to a large , resulting in strong regularization. The model is forced to keep its weights small, trusting our prior belief more than the data.
- Weak Prior (large ): If we are uncertain about the weights, our prior is wide and flat. This leads to a small , resulting in weak regularization. The model is free to fit the data, as in OLS. In the limit as , the prior becomes uniform, , and MAP converges to MLE.
The diagram below visualizes how the MAP estimate is a balance between the data (likelihood) and the prior belief.

The choice of a Gaussian prior leads to L2 regularization. Other priors lead to other forms of regularization. For instance, a Laplace (or double-exponential) prior, which is more sharply peaked at zero, leads to L1 regularization (Lasso), which famously encourages some weights to be exactly zero.

Conclusion
Today, we have forged a crucial link between Bayesian inference and a cornerstone of practical machine learning. By working through the derivation, we have shown that what might appear as a mathematical convenience—adding a penalty term to a loss function—has a deep probabilistic justification.
Key Takeaways:
- MLE and Least Squares: For a linear model with Gaussian noise, the Maximum Likelihood Estimate is identical to the Ordinary Least Squares solution.
- MAP and L2 Regularization: MAP estimation of a linear model's parameters, using a zero-mean Gaussian prior on those parameters, is mathematically equivalent to L2-regularized least squares (Ridge Regression).
- The Regularization Parameter : The hyperparameter is not arbitrary; it represents the ratio of the data noise variance () to the prior belief variance (). It quantifies the balance between trusting the data and trusting our prior belief in a simpler model.
- MLE as a special case of MAP: When the prior is uninformative (e.g., a uniform distribution, or a Gaussian with infinite variance), MAP estimation reduces to MLE. This corresponds to setting the regularization strength to zero.
Preview of the Next Lesson:
Having explored the theoretical underpinnings of MMSE and MAP estimation, it's time to put these ideas into practice. In the next lesson, you will undertake a project: implementing a Bayesian estimator to sequentially update your belief about a coin's bias as new data arrives. This will allow you to see firsthand how a prior distribution is transformed into a posterior distribution with each new observation, solidifying the concepts from this module.