1.3.16Probability & Statistics

Maximum likelihood estimation (MLE)

2,334 words11 min readdifficulty · medium6 backlinks

Overview

Maximum Likelihood Estimation is a method of estimating the parameters of a probability distribution by maximizing a likelihood function, so that under the assumed statistical model the observed data is most probable.

WHY it matters: In ML, we constantly need to fit models (like Gaussian distributions for features, or logistic regression coefficients). MLE gives us a principled, mathematically rigorous way to find the "best" parameters from data.

Figure — Maximum likelihood estimation (MLE)

Core Intuition


The Mathematical Framework


Derivation from First Principles

WHY does the likelihood measure "fit"?

Start with what we actually want: Given data XX, find θ\theta that makes XX most probable.

Step 1: The probability of observing data XX given parameters θ\theta is P(Xθ)P(X|\theta).

Step 2: For independent samples (i.i.d. assumption): P(Xθ)=P(x1,x2,,xnθ)=i=1nP(xiθ)P(X|\theta) = P(x_1, x_2, \ldots, x_n | \theta) = \prod_{i=1}^{n} P(x_i | \theta)

WHY? Independence means joint probability = product of individual probabilities.

Step 3: We treat this as a function of θ\theta (data is fixed), calling it the likelihood L(θX)L(\theta|X).

Step 4: Take logarithm (since log\log is monotonic, argmax\arg\max doesn't change): (θ)=logL(θ)=i=1nlogp(xiθ)\ell(\theta) = \log L(\theta) = \sum_{i=1}^{n} \log p(x_i | \theta)

WHY this step? Mathematically cleaner (sums vs products), numerically stable (prevents underflow), easier derivatives.

Step 5: Find maximum by calculus: θ=0\frac{\partial \ell}{\partial \theta} = 0

Solve for θ\theta → this is θ^MLE\hat{\theta}_{MLE}.


Worked Examples


Common Mistakes & Steel-manning


Properties of MLE


Connection to Machine Learning

Linear Regression as MLE: If errors are Gaussian, minimizing squared loss = maximizing likelihood!

Given y=wTx+ϵy = \mathbf{w}^T\mathbf{x} + \epsilon where ϵN(0,σ2)\epsilon \sim \mathcal{N}(0, \sigma^2): p(yx,w)=12πσ2exp((ywTx)22σ2)p(y|\mathbf{x}, \mathbf{w}) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp\left(-\frac{(y - \mathbf{w}^T\mathbf{x})^2}{2\sigma^2}\right)

Maximize log-likelihood: (w)=12σ2i=1n(yiwTxi)2+const\ell(\mathbf{w}) = -\frac{1}{2\sigma^2}\sum_{i=1}^{n}(y_i - \mathbf{w}^T\mathbf{x}_i)^2 + \text{const}

Maximizing this = minimizing (yiwTxi)2\sum(y_i - \mathbf{w}^T\mathbf{x}_i)^2 = least squares!

Logistic Regression: Also derived via MLE with Bernoulli likelihood.

Neural Networks: Cross-entropy loss = negative log-likelihood for classification.


Mnemonic & Recall

Recall Explain to a 12-year-old

Imagine you have a bag of colored marbles, but you can't see inside. You pull out 10 marbles: 7 red, 3 blue.

Now the question is: "What percentage of the marbles in the bag are red?" You could guess anything—maybe 50% red, maybe 80% red. But which guess makes the most sense given what you pulled out?

MLE says: "Pick the percentage that would make it most likely to pull out exactly 7 red and 3 blue."

If the bag were70% red marbles, pulling out 7 red from 10 tries makes a lot of sense. If it were 10% red, pulling out 7 red would be super weird (very unlikely).

So MLE picks 70% red because that's the percentage that best explains what you actually saw. It's like working backwards from the result to figure out what the bag probably looks like inside.


Connections

  • Bayesian Estimation - MLE vs MAP (prior matters)
  • Fisher Information - Measures how much data tells us about parameters
  • Cramér-Rao Bound - Lower bound on estimator variance
  • Method of Moments - Alternative estimation technique
  • Loss Functions in ML - Cross-entropy, MSE as negative log-likelihoods
  • Gaussian Distribution - Most common MLE application
  • Likelihood Ratio Test - Hypothesis testing using MLE
  • EM Algorithm - MLE for latent variable models
  • Bias-Variance Tradeoff - MLE variance vs bias properties

#flashcards/ai-ml

What is Maximum Likelihood Estimation (MLE)? :: A method of estimating parameters of a probability distribution by finding the parameter values that maximize the likelihood function, making the observed data most probable under the assumed model.

What is the likelihood function for i.i.d. data? :: L(θX)=i=1np(xiθ)L(\theta|X) = \prod_{i=1}^{n} p(x_i|\theta), the product of individual probabilities for each data point.

Why do we use log-likelihood instead of likelihood?
(1) Products become sums (easier calculus), (2) Monotonic so argmax is preserved, (3) Numerically stable (prevents underflow with tiny probabilities).
What is the MLE for the parameter pp of a Bernoulli distribution with kk successes in nn trials?
p^MLE=kn\hat{p}_{MLE} = \frac{k}{n}, the sample proportion of successes.
What is the MLE for the mean μ\mu of a Gaussian distribution (known variance)?
μ^MLE=xˉ=1ni=1nxi\hat{\mu}_{MLE} = \bar{x} = \frac{1}{n}\sum_{i=1}^{n}x_i, the sample mean.
What are the three steps to find MLE analytically?
(1) Write log-likelihood (θ)\ell(\theta), (2) Take derivative ddθ\frac{d\ell}{d\theta}, (3) Set to zero and solve for θ\theta.
What is the relationship between least squares regression and MLE?
Under Gaussian noise assumption, minimizing squared loss is equivalent to maximizing the likelihood function.

Is MLE always unbiased? :: No! MLE is asymptotically unbiased (consistent) but can be biased for finite samples. Example: MLE for Gaussian variance uses 1n\frac{1}{n} instead of 1n1\frac{1}{n-1}.

What is the invariance property of MLE?
If θ^MLE\hat{\theta}_{MLE} is the MLE for θ\theta, then g(θ^MLE)g(\hat{\theta}_{MLE}) is the MLE for g(θ)g(\theta) for any function gg.
What does "asymptotic efficiency" of MLE mean?
MLE achieves the Cramér-Rao lower bound asymptotically, meaning no other consistent estimator has lower variance for large sample sizes.
Why do we assume i.i.d. (independent and identically distributed) samples in MLE?
So the joint probability factorizes as a product: P(Xθ)=P(xiθ)P(X|\theta) = \prod P(x_i|\theta), allowing us to write the likelihood function.
How is cross-entropy loss related to MLE?
Cross-entropy loss is the negative log-likelihood for classification problems. Minimizing cross-entropy = maximizing likelihood under a categorical/Bernoulli model.

Concept Map

iid samples

product of probabilities

take log, monotonic

easier calculus and stable

differentiate wrt theta

solve

maximizes probability of data

used to fit

example

Observed Data X

Probability Model p x given theta

Likelihood Function L

Log-Likelihood

Sum of log probabilities

Set derivative to zero

MLE estimate theta hat

ML Models Gaussian, Logistic

Bernoulli Distribution

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Maximum Likelihood Estimation (MLE) ka matlab hai ki ap data dekh kar wo parameters dhoondte ho jouss data ko sabse zyada probable banate hain. Socho ki tumhare pas kuch observations hain—jaise 10 coin flips mein 7 heads aye. Ab sawaal hai: coin kitna biased hai? Matlab, heads ka probability kya hai?

MLE kehta hai: "Wo probability value choose karo jo is result (7 heads out of 10) ko sabse likely banaye." Agar coin 70% heads deta hai, toh 7 heads milna makes sense. Agar 10% heads deta hai, toh 7 heads milna bahut rare event hoga. Toh MLE bolega p=0.7 best fit hai.

Machine learning mein yeh concept har jagah use hota hai. Jab tum linear regression fit karte ho (squared loss minimize karte ho), actually tum Gaussian likelihood maximize kar rahe ho—wahi MLE hai! Jab neural network train karta ho cross-entropy loss se, woh bhi MLE hai Bernoulli/Categorical distribution ke liye. Matlab, ML ka pora foundation MLE pe based hai. Understanding this makes you understand WHY we use certain loss functions, WHY least squares works, aur WHY probabilistic models itne powerful hain.

Formula simple hai: log-likelihood likho (product ko sum banao), derivative lo, zero pe set karo, solve karo. Bass! Har distribution ke liye yeh process repeat karo—Bernoulli ho, Gaussian ho, ya koi aur—aur tumhe optimal parameters mil jayenge data se. Yeh AI-ML ke sabse fundamental tools mein se ek hai.

Go deeper — visual, from zero

Test yourself — Probability & Statistics

Connections