Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 21

Maximum Likelihood Estimation Explained

Recommended resources

Hello! Welcome back to our module on Statistical Inference and Estimation.

In the last lesson, we focused on the crucial first step of a powerful estimation method: how to formulate the likelihood and log-likelihood functions. We learned that the likelihood function measures how plausible a set of model parameters are, given the data we've observed.

Today, we will build directly on that foundation to understand the core principle of Maximum Likelihood Estimation (MLE). Your learning outcome for this lesson is to explain the principle of Maximum Likelihood Estimation (MLE). This means going beyond just setting up the function and understanding the "why" and "how" of the entire process. This principle is not just a statistical curiosity; it's the engine behind how many machine learning models are trained and is central to your goal of understanding why models work the way they do.

1. The Core Idea: Finding the Best-Fitting Distribution

Imagine you have a set of data points, and you suspect they come from a certain type of probability distribution (e.g., a Normal distribution), but you don't know its specific parameters (e.g., the mean and standard deviation). How would you pick the "best" parameters?

The principle of Maximum Likelihood Estimation gives us a clear answer: Choose the parameters that make your observed data most probable.

Let's watch a video from StatQuest that illustrates this idea beautifully. It uses an example of mouse weights to show how we can visually "slide" a Normal distribution around and change its width until it provides the best possible fit for the data we actually saw.

Maximum Likelihood, clearly explained!!!

This video, titled 'Maximum Likelihood, clearly explained!!!' from StatQuest with Josh Starmer, provides an excellent intuitive and visual explanation of the core principle of MLE.

Watch from the beginning to 5:02. As you watch, focus on these key ideas: The goal is to fit a chosen distribution (a model) to the data. How the 'likelihood' of observing the data changes as you try different parameters (first the mean, then the standard deviation). The 'Maximum Likelihood Estimate' is simply the parameter value that results in the highest likelihood.

As the video demonstrates, MLE is an optimization problem. We are searching through all possible values of our model's parameters () to find the one specific set of values () that maximizes the likelihood function, .

Maximum Likelihood Estimation (MLE) for Normal Distribution Mean
This diagram shows the complete MLE process for a Normal distribution. On the left, we see a sample of data points. On the right, the mathematical steps are laid out: starting with the probability density function (PDF), building the likelihood function, taking its log, and finally using calculus to find the mean (\(\mu\)) that maximizes the function, which turns out to be the sample mean.

2. Why We Need a Model: Constraints and Assumptions

You might wonder: to make the data "most likely," why don't we just create a "magic" model that perfectly reproduces the exact data points we saw and gives zero probability to everything else?

This is a great question, and it highlights a key aspect of MLE: we operate under the constraints of a pre-defined probability model. We don't just find any function that maximizes the data's probability; we find the best parameters for a specific family of distributions (like Normal, Bernoulli, etc.) that we believe is a good representation of the underlying data-generating process.

The following video explains this concept very well.

Maximum Likelihood Estimation ... MADE EASY!!!

In this video, 'Maximum Likelihood Estimation ... MADE EASY!!!' from Stats with Brian, the presenter uses the idea of a 'magic coin' to explain why we need to impose the structure of a probability model on our estimation problem.

Watch the first 2 minutes and 50 seconds (0:00 - 2:50). Pay attention to the distinction between an 'unrestricted' solution (the magic coin) and a 'restricted' one where we assume the coin follows a standard probabilistic model (a Bernoulli distribution with parameter 'P').

By assuming a model, we are making a powerful generalization. Instead of just describing our sample, we are creating a model that can describe the broader population from which the sample was drawn.


3. The Maximization Process: From Calculus to Loss Functions

In the previous lesson, we established that maximizing the likelihood is the same as maximizing the log-likelihood, and that this is mathematically and computationally much easier.

So, the principle of MLE is formally stated as finding the parameters that solve this problem:

How do we solve this? This is where your calculus knowledge becomes very practical. To find the maximum of a function, we can:

  1. Take the derivative of the function with respect to the parameter(s).
  2. Set the derivative equal to zero.
  3. Solve for the parameter(s).

This process finds the "peak" of the log-likelihood curve, where the slope is zero.

The following reading provides a formal, step-by-step summary of this principle.

Introduction to Maximum Likelihood Estimation (MLE)

This article, 'Introduction to Maximum Likelihood Estimation (MLE)' from DataCamp, formalizes the steps we've been discussing.

Please read the section 'How to Derive the MLE Formula'. This section consolidates everything we've covered: defining a model, writing the likelihood, using the log-likelihood, and finally, using calculus (differentiation) to find the optimal parameter value.

The Bridge to Machine Learning: Minimizing Loss

In machine learning, we usually frame problems in terms of minimizing a loss function (or cost function), which measures how "bad" a model's predictions are. How does this connect to maximizing likelihood?

The connection is simple but powerful: Maximizing the log-likelihood is equivalent to minimizing the Negative Log-Likelihood (NLL).

By finding the that minimizes this NLL loss, we are, by definition, finding the Maximum Likelihood Estimate. This reframing is incredibly important because it means that many common ML models (like logistic regression) are trained simply by using an optimization algorithm (like gradient descent) to find the parameters that minimize the NLL of the training data.

This is the "why" you've been looking for: when you train a model by minimizing a cross-entropy or NLL loss, you are implicitly finding the MLE for that model's parameters.

22.7. Maximum Likelihood

This article from the 'Dive into Deep Learning' book provides a fantastic, ML-centric perspective on MLE, directly framing it as an optimization problem.

Read the section '22.7.2. Numerical Optimization and the Negative Log-Likelihood'. Focus on why we work with the negative log-likelihood and how it can be treated as a loss function to be optimized, for example, with gradient descent (as shown in the code samples).

Test your understanding!

You observe the following sequence from a series of coin flips: Heads, Tails, Heads, Heads, Tails.

You want to decide which of two coins is more likely to have produced this sequence:

  • Coin A: A fair coin, where .
  • Coin B: A biased coin, where .

According to the principle of maximum likelihood, which coin is the better model for the data you observed? You don't need to find the true MLE, just compare the likelihood of the data under each model.

Hint: Calculate for each coin.

Show answer

The observed data has 3 Heads and 2 Tails. Let's calculate the likelihood for each coin.

For Coin A ():
The probability of the sequence H, T, H, H, T is:

For Coin B ():
The probability of the sequence H, T, H, H, T is:

Since , the likelihood of observing our data is higher with Coin B. Therefore, according to the principle of maximum likelihood, Coin B () is the better model for this specific dataset.


Conclusion

Excellent work! You have now grasped one of the most fundamental principles in both statistics and machine learning.

Key Takeaways:

  • The Principle of MLE: To estimate the parameters of a model, choose the parameter values that maximize the likelihood (the probability) of observing the data you have collected.
  • A Constrained Search: MLE finds the best parameters within a chosen probability model (e.g., finding the best mean for a Normal distribution).
  • The Process: We maximize the log-likelihood function. This is often done analytically by using calculus (taking the derivative, setting to zero, and solving) or numerically using optimization algorithms.
  • Connection to Machine Learning: Maximizing the log-likelihood is equivalent to minimizing the Negative Log-Likelihood (NLL). The NLL is a very common loss function used to train classification and other probabilistic models.

Preview of the Next Lesson:

We have now covered the "what" (formulating the function) and the "why" (the principle of maximizing it). In the next lesson, "Apply MLE to find the parameters of a simple model," we will do the "how." You'll apply your calculus skills to take the log-likelihood functions we've discussed, find their derivatives, and solve for the maximum likelihood estimators of common distributions like the Bernoulli, Poisson, and Normal.