Maximum Likelihood Estimation › Example
Machine Learning from ScratchAll chapters Maximum Likelihood Estimation › ExampleSection view · Sections in this chapter6 / 10 ↓
Reading tools Definitions, links & notes
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
We now work through the likelihood calculations for two small examples. The first example is a Bernoulli problem with a count. The second is a Gaussian problem with five observations. In both cases, the same pattern appears. Build the likelihood, take its logarithm, differentiate, solve the score equation, then inspect curvature.
Bernoulli: twelve clicks in twenty visits
Suppose twenty visitors arrive, and twelve click. We model each visit as an independent Bernoulli trial with unknown click probability . The observed count is and the number of trials is . The likelihood is
where:
- : the likelihood of the click probability given the observed counts
- : the unknown click probability
- the exponents and : the numbers of clicks and non-clicks, so the terms carry the success and failure counts
The log-likelihood is
The score is
Setting the score to zero gives
Cross-multiplying gives , so , and therefore . Hence
The second derivative is
At , this is
where:
- : the second derivative of the Bernoulli log-likelihood evaluated at
- : the magnitude of the negative second-derivative contribution from the 12 successes
- : the magnitude of the negative second-derivative contribution from the 8 failures
The observed information is therefore , so the approximate standard error is
where:
- : the approximate standard error of the Bernoulli estimate
- : the observed information rounded
This matches the formula .
We can compare the log-likelihood at a few candidate values. At ,
At ,
At ,
The largest value is at , as expected. The differences in log-likelihood are modest, which is another way of seeing that is not absurdly implausible with only twenty observations. A rough 95% Wald interval is , or approximately . The interval is symmetric around and can be unreliable near the boundaries, but it gives a useful first summary of uncertainty.
Gaussian: five sensor readings
Suppose five readings from a sensor are
We model them as independent draws from . The sample mean is
where:
- : the maximum likelihood estimate of the mean
- : the sample mean
- the numerator: the sum of the five observed readings
- the denominator : the number of observations
The deviations from the mean are . Squaring and summing gives
where:
- : the sum of squared deviations of the readings from the sample mean
- each squared term: one observation's deviation from the mean, squared
The maximum likelihood variance is therefore
The maximum likelihood standard deviation is
where:
- : the maximum likelihood standard deviation
- : the maximum likelihood variance estimate
For comparison, the unbiased sample variance divides by :
where:
- : the unbiased sample variance, which divides by rather than
- : the square root of the unbiased sample variance; itself is generally biased for
- : the degrees of freedom, one less than the number of observations
The maximum likelihood variance is smaller because it divides by . On average, it underestimates the true variance by a factor of . With only five observations, the bias is not negligible.
The bias is easiest to see as a ratio. The maximum likelihood variance has expected value , while the unbiased sample variance has expected value . The gap closes as increases.
PythonIn [11]Expand
variance_bias_n = np.arange(2, 51)
variance_bias_mle_ratio = (variance_bias_n - 1) / variance_bias_n
variance_bias_unbiased_ratio = np.ones_like(variance_bias_n)VisualizationOut [12]Expand

The score for at the estimate is
where:
- : the score evaluated at
- : the maximum likelihood variance estimate,
- : each observation's deviation from the candidate mean
The score is zero at , which is exactly the first-order condition for the maximum.
The approximate standard error of the mean, using as the variance, is
where:
- : the approximate standard error of the estimated mean
- : the maximum likelihood variance estimate
- : the number of observations
A rough 95% interval using the normal approximation is , or approximately . With only five observations, a interval based on four degrees of freedom would be wider, which is a reminder that the curvature approximation is asymptotic. The likelihood still gives us the point estimate and a sense of precision, but the finite-sample interval should be chosen with care.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!