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

MLE for Bernoulli Parameters

Hello! Welcome back to our series on the theoretical foundations of AI.

In the previous lesson, we formulated the principle of Maximum Likelihood Estimation (MLE), establishing it as a powerful and theoretically grounded method for finding estimators. We learned that MLE chooses the parameters that make our observed data most probable, and that this is equivalent to minimizing the KL Divergence between our model and the true data-generating distribution.

Today, we move from principle to practice. Your learning outcome is to derive the MLE for the parameter of a Bernoulli distribution. This will be our first complete application of the MLE "recipe":

  1. Formulate the likelihood and log-likelihood functions.
  2. Use calculus to find the parameter value that maximizes this function.
  3. Verify that this value is indeed a maximum.

This exercise will solidify your understanding of the MLE process and yield a result that is both mathematically sound and highly intuitive.

1. The Bernoulli Distribution and its Likelihood

Let's start by recalling the Bernoulli distribution. It models a single trial with two outcomes, typically labeled 1 (success) and 0 (failure). The probability of success is given by a single parameter, which we'll call .

The Probability Mass Function (PMF) for a Bernoulli-distributed random variable can be written compactly as:

You can verify that if you plug in , you get , and if you plug in , you get .

Now, assume we have a dataset consisting of independent and identically distributed (i.i.d.) Bernoulli trials. Our task is to find the MLE for the parameter .

The following video provides a clear, step-by-step derivation of the likelihood and log-likelihood functions for this exact scenario.

Maximum Likelihood Estimation for the Bernoulli Distribution

This video from MIFASA Pty Ltd walks through the initial steps of setting up the MLE problem for the Bernoulli distribution. It shows how to construct the joint likelihood function from the PMF of individual trials and then simplify it into the log-likelihood function.

Please watch from the beginning until 06:50. Pay close attention to: How the joint likelihood function is formed as a product of individual PMFs. The use of exponent rules to simplify the product expression. The application of logarithm rules to convert the final likelihood into the log-likelihood function.

Summarizing the Log-Likelihood

As demonstrated in the video, the derivation proceeds as follows:

  1. Likelihood Function: Due to the i.i.d. assumption, the likelihood is the product of the individual probabilities:

    Using exponent rules, this simplifies to:

  2. Log-Likelihood Function: Taking the natural logarithm transforms the product and exponents:

To make this expression cleaner, let's define as the total number of successes (heads, 1s) and as the total number of failures (tails, 0s). The log-likelihood function is then:

Maximum Likelihood: Bernoulli Example
This image provides a clear visual summary of the Bernoulli log-likelihood function, showing how the sum of individual outcomes (successes and failures) directly forms the coefficients in the final expression.

2. Deriving the Maximum Likelihood Estimate

Now that we have our objective function, , we need to find the value of that maximizes it. Since this is a differentiable function with respect to , we can use calculus. This involves finding the derivative, setting it to zero to find critical points, and using the second derivative to confirm that our critical point is a maximum.

This process connects directly to the unconstrained optimization theory we covered in Module 4.

The following text provides a concise, formal derivation of the MLE for the Bernoulli parameter, which you can use as a reference.

10-315 Notes Maximum Likelihood Estimation

These notes from a Carnegie Mellon University course provide a rigorous and clean derivation for the Bernoulli MLE.

Please read section 3.5.2 titled 'Bernoulli' (page 9). This section shows the complete derivation, from the log-likelihood formulation to solving for the parameter \hat{\phi}_{MLE}. Note that it uses \phi for the parameter instead of p, and N_H, N_T instead of N_1, N_0, but the logic is identical.

Let's walk through the steps of the derivation together.

Step 1: Differentiate the Log-Likelihood

We take the first derivative of with respect to :

Using the rules for differentiating logarithms () and the chain rule for the second term, we get:

Step 2: Set Derivative to Zero and Solve

To find the critical point, we set the derivative to zero and solve for :

Now, we cross-multiply:

Since (the total number of trials), we have:

Solving for gives us the maximum likelihood estimate, :

This result is remarkably intuitive: the MLE for the probability of success in a series of Bernoulli trials is simply the proportion of successes observed in the data, also known as the sample mean.

Test your understanding!

You flip a coin, which you suspect might be biased, 100 times. You observe 65 heads and 35 tails. What is the maximum likelihood estimate for the probability of this coin landing on heads?

Show answer

The number of trials is . The number of successes (heads) is .
The MLE for the probability of heads, , is the proportion of successes:

This aligns perfectly with our intuition. The most likely value for the coin's bias is the one that reflects the frequency we observed.

Step 3: Verify the Maximum with the Second Derivative Test

To be mathematically rigorous, we must confirm that this critical point corresponds to a maximum, not a minimum or saddle point. We do this by checking the sign of the second derivative.

Let's continue with the video, which explicitly calculates the second derivative and analyzes its sign to complete the proof.

Maximum Likelihood Estimation for the Bernoulli Distribution

This final segment of the video completes the derivation by performing the second derivative test, confirming that our estimate for 'p' is indeed a maximum.

Please watch from 06:50 to the end. Focus on: The calculation of the second derivative of the log-likelihood function. The algebraic steps to solve for \hat{p} after setting the first derivative to zero. The logical argument for why the second derivative is always negative, which proves the function is maximized at \hat{p}.

As the video explained, the second derivative of the log-likelihood is:

Let's analyze this expression:

  • and are counts, so they are non-negative ().
  • For any valid probability , the terms and are strictly positive.
  • Therefore, and are both non-negative.

The second derivative is . As long as we have at least one success and one failure (so the problem is non-trivial), this expression is strictly negative. A negative second derivative confirms that the function is concave and our critical point is a local maximum. For a concave function, this local maximum is also the unique global maximum.

Conclusion

Congratulations! You have successfully completed your first end-to-end derivation of a Maximum Likelihood Estimator. We applied the general principle learned in the last lesson to a concrete distribution and, using calculus, arrived at a simple and intuitive result.

Key Takeaways:

  • The log-likelihood function for i.i.d. Bernoulli trials with parameter is , where and are the counts of successes and failures.
  • By differentiating, setting to zero, and solving, we found the MLE for the Bernoulli parameter: . This is simply the sample mean, or the proportion of successes.
  • The second derivative test confirms that this solution maximizes the log-likelihood function, fulfilling the requirement for mathematical rigor.

Preview of the Next Lesson:
We have now applied MLE to a discrete distribution. In the next lesson, we will tackle a continuous one: the Gaussian (or Normal) distribution. You will derive the MLE for the parameters ( and ) of a Gaussian distribution. This will introduce a new challenge: optimizing a function with respect to multiple parameters simultaneously, which will require the use of partial derivatives.

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

Sign up