Maximum likelihood estimation

core 11 minprobabilityestimationlikelihood

Builds on:Common distributions

The idea

You have data and a family of models indexed by a parameter θ\theta. Every candidate θ\theta assigns the observed data some probability. Maximum likelihood says: choose the θ\theta that made what you saw least surprising.

θ^MLE=arg⁡max⁡θ  L(θ)=arg⁡max⁡θ∏i=1np(xi∣θ)\hat{\theta}_{\text{MLE}} = \arg\max_\theta \; L(\theta) = \arg\max_\theta \prod_{i=1}^n p(x_i \mid \theta)

In practice you always work with the log-likelihood ℓ(θ)=∑ilog⁡p(xi∣θ)\ell(\theta) = \sum_i \log p(x_i \mid \theta): the product becomes a sum, underflow disappears, derivatives are clean, and the argmax is unchanged. The recipe is mechanical: write ℓ\ell, differentiate, set to zero, check the second derivative is negative.

Three reasons this one idea keeps reappearing:

  1. It recovers the obvious estimators. The MLE of a Bernoulli pp is the sample proportion; of a Poisson λ\lambda or Gaussian μ\mu, the sample mean. The principled machinery agrees with intuition on easy cases, which is what licenses trusting it on hard ones.
  2. It is what your loss functions secretly are. Least squares is MLE under Gaussian noise; cross-entropy is the negative Bernoulli/categorical log-likelihood; Poisson regression's loss is the negative Poisson log-likelihood. "Pick a noise model, take negative log" generates most of the standard losses.
  3. It has strong guarantees — asymptotically. MLEs are consistent (converge to the truth), asymptotically normal (enabling standard errors and Wald tests), asymptotically efficient (no unbiased estimator does better in the limit), and invariant (MLE of g(θ)g(\theta) is g(θ^)g(\hat{\theta})).

The fine print: those guarantees are large-sample. In small samples MLEs can be biased — the Gaussian variance MLE divides by nn instead of n−1n-1 — and with sparse data they hit degenerate boundary answers, like estimating a probability of exactly zero because an event never occurred in 20 trials. The standard fix is a prior: MAP estimation maximizes likelihood ×\times prior, and its negative log is exactly "loss + regularizer".

Worked example

Ten independent trials, seven successes. Model: Bernoulli(p)(p).

ℓ(p)=7log⁡p+3log⁡(1−p)\ell(p) = 7 \log p + 3 \log(1 - p)

Differentiate and solve:

ℓ′(p)=7p−31−p=0  ⇒  7(1−p)=3p  ⇒  p^=0.7\ell'(p) = \frac{7}{p} - \frac{3}{1-p} = 0 \;\Rightarrow\; 7(1-p) = 3p \;\Rightarrow\; \hat{p} = 0.7

Numeric sanity check (natural logs):

ppℓ(p)\ell(p)
0.510log⁡0.5=−6.9310 \log 0.5 = -6.93
0.77log⁡0.7+3log⁡0.3=−6.117 \log 0.7 + 3 \log 0.3 = \mathbf{-6.11}
0.97log⁡0.9+3log⁡0.1=−7.657 \log 0.9 + 3 \log 0.1 = -7.65

p=0.7p = 0.7 wins, and note the asymmetry: 0.9 is worse than 0.5 despite being the same distance from 0.7, because those three failures are very improbable under p=0.9p = 0.9 — the log⁡\log of a small probability is savagely negative. That asymmetry is the same mechanism that makes cross-entropy punish a confident wrong prediction so much harder than a hedged one.

Cheat sheet

Recipe: write ℓ(θ)=∑ilog⁡p(xi∣θ)\ell(\theta) = \sum_i \log p(x_i \mid \theta) → solve ℓ′(θ)=0\ell'(\theta) = 0 → verify ℓ′′(θ^)<0\ell''(\hat{\theta}) < 0.

ModelMLENote
Bernoulli / binomial ppk/nk/nsample proportion
Poisson λ\lambdaxˉ\bar{x}sample mean
Gaussian μ\muxˉ\bar{x}sample mean
Gaussian σ2\sigma^21n∑(xi−xˉ)2\frac{1}{n}\sum(x_i - \bar{x})^2biased low; unbiased uses n−1n - 1
Exponential λ\lambda1/xˉ1/\bar{x}via invariance from mean =1/λ= 1/\lambda

Loss ↔ likelihood dictionary:

Properties (large nn): consistent · asymptotically normal · asymptotically efficient (Cramer-Rao) · invariance: g(θ)^=g(θ^)\widehat{g(\theta)} = g(\hat{\theta}).

Gotchas: