Recommended resources
The freely available resources this lesson will direct you to.
Hello! Welcome to your next lesson on the theoretical foundations of AI.
In our last session, you successfully derived the Maximum Likelihood Estimator (MLE) for a Bernoulli distribution. This gave you a complete, hands-on application of the MLE framework for a discrete distribution with a single parameter. We followed the core "recipe": formulating the log-likelihood, differentiating, and solving for the parameter that maximizes the probability of our observed data.
Today, we will build directly on that foundation. Your learning outcome is to derive the MLE for the parameters (mean and variance ) of a Gaussian distribution. This is a cornerstone of classical statistics and a fundamental building block for many machine learning models.
This lesson will introduce a key new element: optimizing a function with respect to multiple parameters. This will require you to apply your knowledge of multivariate calculus by computing partial derivatives and solving a system of first-order conditions, just as we discussed in Modules 3 and 4.
1. The Gaussian Distribution and its Log-Likelihood
Let's begin. The Gaussian (or Normal) distribution is arguably the most important continuous probability distribution. Its probability density function (PDF) for a random variable with mean and variance is:
Our goal is to find the values for the parameters and that best explain a given dataset.
Assume we have a dataset of observations, , which we assume are independent and identically distributed (i.i.d.) according to a Gaussian distribution with unknown and .
The following video provides a concise and rigorous derivation of the log-likelihood function for this scenario. It follows the exact same logical steps we used for the Bernoulli distribution: write the joint probability as a product (the likelihood), and then take the logarithm to simplify it into a sum.
Maximum Likelihood Estimation Example: Fitting a Normal Distribution with Data
This video by Steve Brunton on YouTube provides a clear, step-by-step derivation of the log-likelihood function for the Gaussian distribution. It's mathematically direct and aligns well with our focus on rigorous proofs.
Please watch from 01:00 to 08:11. Pay close attention to: How the joint PDF (the likelihood function) is constructed from the individual PDFs due to the i.i.d. assumption. The rules of logarithms that transform the product into a sum. The careful simplification of the log of each term (the normalization constant and the exponential) to arrive at the final log-likelihood function.
Summarizing the Log-Likelihood Function
As derived in the video, the process unfolds as follows:
-
Likelihood Function: The joint PDF for our i.i.d. samples is the product of the individual PDFs:
This can be grouped into: -
Log-Likelihood Function: Taking the natural logarithm simplifies this expression significantly:
Applying logarithm rules, this becomes:
Or, equivalently, by separating the term:
This final expression is our objective function. We need to find the and that maximize it.
2. Deriving the MLE for Mean () and Variance ()
To maximize a function of two variables, we find the partial derivatives with respect to each variable and set them to zero. This gives us a system of two equations with two unknowns ( and ), which we can then solve.
This procedure is demonstrated clearly in the remainder of the video and also laid out in the following text. The text offers a very clean, equation-based summary of the derivation.
Normal distribution - Maximum likelihood estimation
This page from Statlect provides a concise and formal derivation of the MLE for both the mean and variance of a normal distribution. It's a great reference to have alongside the video.
Please read the section titled 'The maximum likelihood estimators'. This section shows the partial derivatives of the log-likelihood function being taken with respect to \mu and \sigma^2, set to zero, and solved. Notice that it differentiates with respect to \sigma^2 directly, which is a very clean approach.
Let's perform the derivation step-by-step.
Step 1: Differentiate with respect to and solve
We take the partial derivative of with respect to , treating as a constant. The first two terms of the log-likelihood do not depend on , so their derivatives are zero.
Using the chain rule:
Now, set the partial derivative to zero to find the critical point:
Assuming , this simplifies to:
This gives us the MLE for the mean, :
This is a very intuitive result: the most likely value for the population mean is the sample mean of the data.
Step 2: Differentiate with respect to and solve
Next, we take the partial derivative of with respect to , treating as a constant.
Let's differentiate term by term:
Since , we have .
Set this to zero and solve for :
Multiply both sides by :
This gives us the MLE for the variance. To get the final estimator, we plug in the value we already found for the mean, :
The maximum likelihood estimate for the variance is the sample variance, calculated using the MLE for the mean.
Test your understanding!
Suppose you measure the height of 4 people from a certain population and get the following data (in cm): . Assuming the heights are normally distributed, what are the maximum likelihood estimates for the mean and variance of the population's height?
Show answer
First, we calculate the MLE for the mean, , which is the sample mean:
Next, we use this value to calculate the MLE for the variance, :
So, the MLEs are and .
A Note on Rigor and Bias
For full mathematical rigor, one would need to compute the Hessian matrix (the matrix of second-order partial derivatives) and check that it is negative definite at this critical point, confirming it is a maximum. For the Gaussian log-likelihood, this is indeed the case.
It is also important to note a key property of the variance estimator we just derived. The estimator is a biased estimator of the true population variance. The unbiased estimator, which you may have seen elsewhere, uses a denominator of . However, the MLE procedure correctly yields the version. While biased, is consistent, meaning the bias approaches zero as the sample size grows.
Conclusion
Excellent work. You have now successfully derived the Maximum Likelihood Estimators for the two parameters of a Gaussian distribution. This process reinforced the MLE recipe and extended it to a multi-parameter, continuous case.
Key Takeaways:
- The MLE framework is general and applies to both discrete and continuous distributions with any number of parameters.
- For multi-parameter problems, finding the MLE involves taking partial derivatives of the log-likelihood with respect to each parameter and solving the resulting system of equations.
- The MLE for the mean () of a Gaussian distribution is the sample mean.
- The MLE for the variance () is the sample variance with a denominator, which is a biased but consistent estimator.
Preview of the Next Lesson:
So far, our estimation has been driven purely by the data. The principle of Maximum Likelihood finds the parameters that make the observed data most probable. In our next lesson, we will introduce Maximum a Posteriori (MAP) estimation. MAP extends MLE by allowing us to incorporate prior beliefs about the parameters into the estimation process. This is a crucial step toward Bayesian inference and will provide a richer framework for statistical modeling.