Hello! Welcome to the next lesson in our journey through Statistical Inference and Estimation.
In our last session, we explored the foundational principle of Maximum Likelihood Estimation (MLE). We learned that MLE is about choosing the model parameters that make our observed data most probable. We also saw how this is equivalent to maximizing the log-likelihood, or, crucially for machine learning, minimizing the Negative Log-Likelihood (NLL).
Today, we transition from the "why" to the "how." Your learning outcome is to apply MLE to find the parameters of a simple model (e.g., for a Bernoulli or Normal distribution). We will roll up our sleeves and use the calculus concepts we've reviewed to derive the estimators for these two fundamental distributions. This lesson is key to your goal of understanding the statistical justification behind common modeling practices. You'll see that the familiar statistics you've used before, like the sample mean, don't just feel right—they are often the "best" estimates according to the powerful principle of MLE.
The 5-Step Recipe for Finding MLEs
The process of deriving a Maximum Likelihood Estimator analytically can be broken down into five clear steps. We'll use this recipe for both of our examples today.
- Define the Model and its Probability Function: Start with the probability mass function (PMF) for discrete data or the probability density function (PDF) for continuous data of a single observation, , where is the parameter we want to estimate.
- Construct the Likelihood Function: Assuming the data points are independent and identically distributed (IID), the likelihood of observing the entire dataset is the product of the individual probabilities: .
- Construct the Log-Likelihood Function: Take the natural logarithm of the likelihood function. This converts the product into a more manageable sum: .
- Differentiate and Set to Zero: Find the derivative of the log-likelihood function with respect to the parameter . Set this derivative equal to zero to find the point of maximum likelihood: .
- Solve for the Parameter: Algebraically solve the equation from the previous step for . The solution, denoted , is the Maximum Likelihood Estimator.
Now, let's put this recipe into practice.
Example 1: MLE for the Bernoulli Distribution
The Bernoulli distribution models a single trial with a binary outcome: success (1) or failure (0). The single parameter to estimate is , the probability of success. Think of this as modeling a coin flip, a user clicking on an ad, or a patient responding to a treatment.

Let's derive the MLE for . The following video provides a clear, step-by-step walkthrough of the entire process. I've broken down the key sections for you to watch.
Maximum Likelihood Estimation for the Bernoulli Distribution
This video, 'Maximum Likelihood Estimation for the Bernoulli Distribution', will guide us through the mathematical derivation step-by-step.
First, watch from the beginning to 6:50. This part covers the first three steps of our recipe: Defining the Bernoulli PMF. Constructing the likelihood function by multiplying the individual PMFs. Taking the log to get the log-likelihood function and simplifying it using log rules.
As a summary of what you just watched, we start with the PMF for a single observation :
The likelihood for observations is:
And the log-likelihood is:
Now for the calculus. The next part of the video shows how to differentiate this function and solve for .
Maximum Likelihood Estimation for the Bernoulli Distribution
Now, let's see how to apply steps 4 and 5 of our recipe.
Watch from 6:50 to 14:04. This part covers: Taking the derivative of the log-likelihood with respect to p. Setting the derivative to zero. Solving the resulting equation for p to find the MLE.
The derivative of the log-likelihood with respect to is:
Setting this to zero and solving for gives us the Maximum Likelihood Estimator, :
This is a powerful result. It provides a formal justification for what feels intuitive: the best estimate for the probability of success in a population is simply the proportion of successes you observed in your sample.
Test your understanding!
In the derivation, we found that the derivative of with respect to is . Why is there a negative sign in the numerator?
Show answer
This is due to the chain rule from calculus. When differentiating a composite function like , the derivative is .
In our case, the "outer" function is and the "inner" function is .
- The derivative of the outer function is .
- The derivative of the inner function is .
Multiplying them together gives .
Example 2: MLE for the Normal Distribution
Now, let's tackle a continuous distribution. The Normal (or Gaussian) distribution is defined by two parameters: the mean and the variance . We'll derive the MLEs for both. Given your engineering background, you've likely seen this distribution countless times; now we'll prove why the sample mean and variance are its natural estimators.
The math for the Normal distribution is more involved, but the logic is identical. We will again lean on a StatQuest video to make the derivation clear.
Maximum Likelihood For the Normal Distribution, step-by-step!!!
The video 'Maximum Likelihood For the Normal Distribution, step-by-step!!!' by Josh Starmer does an excellent job of breaking down this derivation. We will follow its steps closely.
First, watch from 5:37 to 12:59. This part covers steps 2 and 3 of our recipe for the Normal distribution: How to construct the likelihood function for multiple data points. The crucial process of taking the logarithm and using log rules to simplify the complicated-looking product into a manageable sum (the log-likelihood).
The log-likelihood function for the Normal distribution, after simplification, is:
This expression is much easier to differentiate than the original likelihood function. Since we have two parameters, we will need to take partial derivatives—one with respect to and another with respect to .
Finding the MLE for the Mean ()
Let's find the estimator for the mean first.
Maximum Likelihood For the Normal Distribution, step-by-step!!!
This next segment shows the derivation for the mean, \mu.
Watch from 12:59 to 14:50 and then from 16:59 to 18:03. This will show you: How to take the partial derivative of the log-likelihood with respect to \mu (treating \sigma^2 as a constant). How to set the derivative to zero and solve for \mu.
When we take the partial derivative with respect to and set it to 0, we get:
Solving for gives us the incredibly familiar result:
Once again, the MLE for the population mean is simply the sample mean .
Finding the MLE for the Variance ()
Now let's do the same for the variance.
Maximum Likelihood For the Normal Distribution, step-by-step!!!
Finally, let's watch the derivation for the variance, \sigma^2.
Watch from 14:50 to 16:59 and then from 18:03 to the end (19:29). This segment covers: Taking the partial derivative with respect to \sigma (or \sigma^2). Setting it to zero and solving for \sigma^2.
Taking the partial derivative with respect to and setting it to 0 yields:
When we solve this for (and plug in our already-derived estimator ), we get:
This is the average of the squared differences from the sample mean. You might have seen a version of sample variance with in the denominator. That is the unbiased sample variance, a concept we will explore later. For now, the key insight is that MLE provides a direct derivation for this form of the variance estimator.
Summary and When to Go Numerical
In many cases for common distributions, we can find a closed-form solution for the MLE, as we did today. The following article provides a nice summary table of these solutions.
Introduction to Maximum Likelihood Estimation (MLE)
This DataCamp article, 'Introduction to Maximum Likelihood Estimation (MLE)', which you've seen before, contains a useful summary.
Please read the section 'Closed-form solutions and when they apply' and pay special attention to the table. It neatly summarizes the results we derived today for the Bernoulli and Gaussian distributions, along with others.
However, for more complex models, such as mixture models or many neural network architectures, solving analytically is impossible. In those situations, we rely on numerical optimization algorithms, like Gradient Descent, to iteratively find the parameter values that minimize the Negative Log-Likelihood. This connects directly back to your goal of understanding how ML models are trained.
Conclusion
Congratulations on working through these derivations! This is a significant step in connecting formal statistical theory to practical data modeling.
Key Takeaways:
- We have a 5-step recipe to derive Maximum Likelihood Estimators: define the model, build the likelihood and log-likelihood, differentiate, and solve.
- For a Bernoulli distribution, the MLE of the success probability is the sample proportion of successes.
- For a Normal distribution, the MLE of the mean is the sample mean, and the MLE of the variance is the sample variance with a denominator of .
- The MLE framework provides a rigorous, principled foundation for using these intuitive sample statistics to estimate population parameters.
Preview of the Next Lesson:
This lesson concludes our module on statistical inference and estimation. You've learned how to formulate hypotheses, construct likelihood functions, understand the principle of MLE, and now apply it.
Our next module, "Optimization for Machine Learning," is the perfect follow-up. We will begin by formally defining the role of a loss function in quantifying model error. Having just seen how minimizing the Negative Log-Likelihood is a primary goal in MLE, you are perfectly positioned to understand how loss functions drive the entire training process in machine learning.