Part III — Probability, Information Theory & Bayesian Inference · Chapter 6

Maximum Likelihood Estimation (MLE)

Hook

You flip a coin a handful of times and see mostly heads. What single value of "probability of heads" makes the data you actually saw the least surprising?

Intuition
HHTHH
log-likelihood(p=0.50) = -3.466

Drag the candidate pp across the curve. Every point on it is the log-likelihood of these exact five flips under that one value of pp — and the curve has a single, unambiguous high point.

Formalize

For nn independent Bernoulli trials with kk heads, the likelihood of the data under parameter pp is

L(p)=pk(1p)nkL(p) = p^k (1-p)^{n-k}
  • L(p)L(p) — the likelihood: how probable the observed data is, as a function of pp.
  • kk — the number of heads actually observed.
  • nn — the total number of flips.

Products of small numbers underflow fast, so in practice everyone maximizes the log-likelihood instead — same maximizer, better numerics:

(p)=logL(p)=klogp+(nk)log(1p)\ell(p) = \log L(p) = k\log p + (n-k)\log(1-p)
  1. The log is monotonic, so the peak doesn't move

    log\log is strictly increasing, so whatever pp maximizes L(p)L(p) also maximizes (p)\ell(p) — taking the log never changes where the maximum sits.

  2. Setting the derivative to zero gives a closed form
    ddp=kpnk1p=0\frac{d\ell}{dp} = \frac{k}{p} - \frac{n-k}{1-p} = 0
    1. Move the second term across and cross-multiply: kp=nk1p    k(1p)=p(nk)\frac{k}{p} = \frac{n-k}{1-p} \implies k(1-p) = p(n-k)
    2. Expand both sides: kkp=pnpkk - kp = pn - pk
    3. The kp-kp on the left and pk-pk on the right are the same term, so they cancel, leaving k=pnk = pn

    Dividing both sides by nn gives

    p^=kn\hat{p} = \frac{k}{n}

    — the maximum likelihood estimate is exactly the observed proportion of heads, no search required.

  3. This is the general MLE recipe

    Write the likelihood of the data under a parameter, take its log, and find where the derivative vanishes — the same three steps work for far more complex models than a coin.

Play
HHTHH
p=0.50: log-likelihood = -3.466 (MLE p=0.80 scores -2.502, the best possible)

The curve's exact peak sits at p=0.8p=0.8, matching p^=k/n\hat{p}=k/n exactly — drag away in either direction and the log-likelihood only gets worse, confirming this closed form really is the unique maximizer.

Worked example

Five flips: H, H, T, H, H — so k=4k=4 heads out of n=5n=5.

  1. Apply the closed-form MLE
    p^=kn=45=0.8\hat{p} = \frac{k}{n} = \frac{4}{5} = 0.8
  2. Confirm it by evaluating the log-likelihood at the estimate
    (0.8)=4log(0.8)+1log(0.2)4(0.2231)+(1.6094)2.502\ell(0.8) = 4\log(0.8) + 1\log(0.2) \approx 4(-0.2231) + (-1.6094) \approx -2.502
  3. Check a nearby value scores worse
    (0.6)=4log(0.6)+1log(0.4)4(0.5108)+(0.9163)2.960\ell(0.6) = 4\log(0.6) + 1\log(0.4) \approx 4(-0.5108) + (-0.9163) \approx -2.960

    Worse (more negative) than 2.502-2.502 — exactly what "0.80.8 is the maximizer" predicts.

Checkpoint

4 heads out of 5 flips. Drag p until it lands on the maximum likelihood estimate.

HHTHH
log-likelihood(p=0.50) = -3.466
Drag the slider to try it
Summary
p^=kn=argmaxp[klogp+(nk)log(1p)]\hat{p} = \frac{k}{n} = \arg\max_p \big[k\log p + (n-k)\log(1-p)\big]

Maximum likelihood estimation is this same idea at any scale: write down how probable your data is under a parameter, then find the parameter that makes that probability as large as possible. Logistic regression, neural network training via cross-entropy, and Gaussian curve-fitting are all MLE in disguise.