Skip to main content
© 2026 ePowerAI. All rights reserved.
CoursesContact
eAI
CoursesContact
Week 8: Point Estimation — Maximum Likelihood
Prob & Stats
01Week 1: Probability Spaces and Events
02Week 2: Random Variables and Distributions
03Week 3: Expectation, Variance, and Covariance
04Week 4: Conditioning and Independence
05Week 5: Bayes' Rule and Generative Classification
06Week 6: Multivariate Gaussians
07Week 7: Laws of Large Numbers and the CLT
08Week 8: Point Estimation — Maximum Likelihood
09Week 9: Bayesian Estimation and MAP
10Week 10: Bias, Variance, and Uncertainty
11Week 11: Information Theory for ML
12Week 12: Exponential Families (lite)
13Week 13: Graphical Models (lite)
14Week 14: Capstone — Probabilistic Language of ML
Week 08· Prob & Stats· Inference22 min read

Week 8: Point Estimation — Maximum Likelihood

✦Learning Outcomes
  • Write the likelihood and log-likelihood for i.i.d. data
  • Derive Bernoulli and univariate Gaussian MLEMaximum Likelihood Estimations
  • Explain invariance of MLE under reparameterization at intuition level
  • Connect maximizing likelihood to minimizing cross-entropy (preview Week 11)
◆Prerequisites

Required: Weeks 2–3 (distributions and expectation), Week 7 (LLN — justifies why sample averages are good estimates).

Preview: MLE is the workhorse of classical estimation. Week 9 contrasts it with Bayesian (MAP) estimation, and Week 11 shows MLE ≡ minimising KL divergence to the empirical distribution.

Estimators as Functions of Data#

An estimator θ^=g(X1,…,Xn)\hat \theta = g(X_1, \ldots, X_n)θ^=g(X1​,…,Xn​) is a function that maps a dataset to a guess about the unknown parameter θ\thetaθ. It is a random variable (the data are random), and we judge it by its sampling distribution — bias, variance, and MSE (Week 10).

Example estimators for the mean of a population:

  • Sample mean: μ^=1n∑Xi\hat \mu = \frac{1}{n}\sum X_iμ^​=n1​∑Xi​ — standard choice.
  • Sample median: robust to outliers, less efficient for normal data.
  • Trimmed mean: discards extremes, a compromise.

The question is: which function of the data should we use? Maximum likelihood provides a principled answer: choose the θ\thetaθ that makes the observed data most probable.

Likelihood#

Given i.i.d. data x1,…,xnx_1, \ldots, x_nx1​,…,xn​, the likelihood function is the joint probability (density) viewed as a function of θ\thetaθ:

L(θ)=∏i=1np(xi∣θ).L(\theta) = \prod_{i=1}^n p(x_i \mid \theta).L(θ)=i=1∏n​p(xi​∣θ).

The log-likelihood is almost always easier to work with (sums are friendlier than products, and the log is monotonic so the maximiser is unchanged):

ℓ(θ)=log⁡L(θ)=∑i=1nlog⁡p(xi∣θ).\ell(\theta) = \log L(\theta) = \sum_{i=1}^n \log p(x_i \mid \theta).ℓ(θ)=logL(θ)=i=1∑n​logp(xi​∣θ).

Critical distinction — likelihood vs probability:

  • p(x∣θ)p(x \mid \theta)p(x∣θ) as a function of xxx (with θ\thetaθ fixed) is a probability — it sums/integrates to 1 over xxx.
  • L(θ)=p(x∣θ)L(\theta) = p(x \mid \theta)L(θ)=p(x∣θ) as a function of θ\thetaθ (with xxx fixed) is the likelihood — it does not integrate to 1 over θ\thetaθ. "The likelihood of θ\thetaθ" is not "the probability that θ\thetaθ is true."

The MLEMaximum Likelihood Estimation is the value that maximises the likelihood:

θ^MLE=arg⁡max⁡θL(θ)=arg⁡max⁡θℓ(θ).\hat \theta_{\text{MLE}} = \arg\max_\theta L(\theta) = \arg\max_\theta \ell(\theta).θ^MLE​=argθmax​L(θ)=argθmax​ℓ(θ).

Since log⁡\loglog is monotonic, maximising ℓ\ellℓ is equivalent to maximising LLL.

Bernoulli MLE#

Suppose we observe nnn i.i.d. Bernoulli trials with unknown success probability ppp. The data are x1,…,xn∈{0,1}x_1, \ldots, x_n \in \{0, 1\}x1​,…,xn​∈{0,1}. Let k=∑xik = \sum x_ik=∑xi​ be the number of successes.

The likelihood of ppp given the data:

L(p)=∏i=1npxi(1−p)1−xi=pk(1−p)n−k.L(p) = \prod_{i=1}^n p^{x_i} (1-p)^{1 - x_i} = p^k (1-p)^{n-k}.L(p)=i=1∏n​pxi​(1−p)1−xi​=pk(1−p)n−k.

Log-likelihood:

ℓ(p)=klog⁡p+(n−k)log⁡(1−p).\ell(p) = k \log p + (n - k) \log(1 - p).ℓ(p)=klogp+(n−k)log(1−p).

Set derivative to zero:

dℓdp=kp−n−k1−p=0  ⟹  kp=n−k1−p  ⟹  k(1−p)=(n−k)p  ⟹  p^=kn.\frac{d\ell}{dp} = \frac{k}{p} - \frac{n-k}{1-p} = 0 \;\Longrightarrow\; \frac{k}{p} = \frac{n-k}{1-p} \;\Longrightarrow\; k(1-p) = (n-k)p \;\Longrightarrow\; \hat p = \frac{k}{n}.dpdℓ​=pk​−1−pn−k​=0⟹pk​=1−pn−k​⟹k(1−p)=(n−k)p⟹p^​=nk​.

The MLE for a Bernoulli probability is simply the sample proportion of successes — intuitively the most natural estimate.

Worked numeric example. 7 heads in 10 coin flips. Then p^=0.7\hat p = 0.7p^​=0.7. The log-likelihood at p^=0.7\hat p = 0.7p^​=0.7 is:

ℓ(0.7)=7log⁡(0.7)+3log⁡(0.3)≈−6.11.\ell(0.7) = 7 \log(0.7) + 3 \log(0.3) \approx -6.11.ℓ(0.7)=7log(0.7)+3log(0.3)≈−6.11.

At p=0.5p = 0.5p=0.5 (fair coin hypothesis), ℓ(0.5)=7log⁡(0.5)+3log⁡(0.5)=10log⁡(0.5)≈−6.93\ell(0.5) = 7 \log(0.5) + 3 \log(0.5) = 10 \log(0.5) \approx -6.93ℓ(0.5)=7log(0.5)+3log(0.5)=10log(0.5)≈−6.93, which is lower — the data favour p=0.7p = 0.7p=0.7 over p=0.5p = 0.5p=0.5.

Gaussian MLE#

For i.i.d. data x1,…,xnx_1, \ldots, x_nx1​,…,xn​ assumed to come from N(μ,σ2)\mathcal{N}(\mu, \sigma^2)N(μ,σ2) with both parameters unknown:

Joint density:

L(μ,σ2)=∏i=1n12πσ2exp⁡(−(xi−μ)22σ2).L(\mu, \sigma^2) = \prod_{i=1}^n \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left(-\frac{(x_i - \mu)^2}{2\sigma^2}\right).L(μ,σ2)=i=1∏n​2πσ2​1​exp(−2σ2(xi​−μ)2​).

Log-likelihood:

ℓ(μ,σ2)=−n2log⁡(2π)−n2log⁡σ2−12σ2∑i=1n(xi−μ)2.\ell(\mu, \sigma^2) = -\frac{n}{2}\log(2\pi) - \frac{n}{2}\log\sigma^2 - \frac{1}{2\sigma^2}\sum_{i=1}^n (x_i - \mu)^2.ℓ(μ,σ2)=−2n​log(2π)−2n​logσ2−2σ21​i=1∑n​(xi​−μ)2.

MLE for μ\muμ: Differentiate with respect to μ\muμ (the first two terms do not involve μ\muμ):

∂ℓ∂μ=1σ2∑i=1n(xi−μ)=0  ⟹  μ^=1n∑i=1nxi=xˉ.\frac{\partial \ell}{\partial \mu} = \frac{1}{\sigma^2}\sum_{i=1}^n (x_i - \mu) = 0 \;\Longrightarrow\; \hat \mu = \frac{1}{n}\sum_{i=1}^n x_i = \bar x.∂μ∂ℓ​=σ21​i=1∑n​(xi​−μ)=0⟹μ^​=n1​i=1∑n​xi​=xˉ.

MLE for σ2\sigma^2σ2: Plug μ^\hat \muμ^​ back and differentiate with respect to σ2\sigma^2σ2:

σ^MLE2=1n∑i=1n(xi−xˉ)2.\hat \sigma^2_{\text{MLE}} = \frac{1}{n}\sum_{i=1}^n (x_i - \bar x)^2.σ^MLE2​=n1​i=1∑n​(xi​−xˉ)2.

Note the denominator is nnn, not n−1n-1n−1. The MLE for variance is slightly biased downward (the 1/(n−1)1/(n-1)1/(n−1) version is unbiased — see Week 10). For large nnn, the difference is negligible.

MLE and Training Objectives#

MLE provides a unified lens on many ML training objectives:

  • Linear regression with Gaussian noise: Assuming yi∼N(wTxi,σ2)y_i \sim \mathcal{N}(w^T x_i, \sigma^2)yi​∼N(wTxi​,σ2), the negative log-likelihood is ∝∑(yi−wTxi)2\propto \sum (y_i - w^T x_i)^2∝∑(yi​−wTxi​)2 — exactly the mean squared error loss.
  • Logistic regression: Binary labels modelled as Bernoulli with p=σ(wTx)p = \sigma(w^T x)p=σ(wTx), the negative log-likelihood is the binary cross-entropy loss.
  • Multi-class classification: Categorical likelihood gives the cross-entropy loss with softmax.

The deep connection (preview Week 11): Maximising likelihood is equivalent to minimising the KL divergence between the empirical distribution of the data and the model distribution p(x∣θ)p(x \mid \theta)p(x∣θ). Training a generative model by MLE means: make the model's distribution as close as possible (in KL sense) to the data distribution.

Invariance of MLE: If θ^\hat \thetaθ^ is the MLE for θ\thetaθ, then g(θ^)g(\hat \theta)g(θ^) is the MLE for g(θ)g(\theta)g(θ) for any one-to-one function ggg. Example: the MLE for standard deviation σ\sigmaσ is σ^MLE2\sqrt{\hat \sigma^2_{\text{MLE}}}σ^MLE2​​. This property does not hold for unbiased estimators in general.

Exercise · Fill in the blank

You observe 15 heads in 25 independent coin flips. What is the MLE of the probability of heads? Enter as a decimal.


Knowledge check#

Question 1 of 4

Why do we maximise log-likelihood instead of likelihood?

Log is monotonic and turns products into sums
Log-likelihood is always larger
Likelihood cannot be differentiated
Log makes the estimator unbiased

Browser lab#

Plot the log-likelihood of Bernoulli ppp for a fixed dataset and mark the MLE.

python · runs in browser
import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(7)
n, p_true = 30, 0.65
data = rng.binomial(1, p_true, size=n)
k = data.sum()

def log_lik(p):
    if p <= 0 or p >= 1:
        return -np.inf
    return k * np.log(p) + (n - k) * np.log(1 - p)

p_grid = np.linspace(0.01, 0.99, 200)
ll_vals = np.array([log_lik(p) for p in p_grid])
p_mle = k / n

fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(p_grid, ll_vals, "tab:blue", linewidth=2, label="log-likelihood ℓ(p)")
ax.axvline(p_true, color="tab:green", linestyle="--", linewidth=1.5, label=f"True p={p_true}")
ax.axvline(p_mle, color="tab:red", linestyle="--", linewidth=1.5, label=f"MLE p̂={p_mle:.3f}")
ax.scatter([p_mle], [log_lik(p_mle)], color="tab:red", s=80, zorder=5)
ax.set_xlabel("p")
ax.set_ylabel("ℓ(p)")
ax.set_title(f"Log-likelihood of p — {k} heads in {n} flips")
ax.legend()
plt.tight_layout()
plt.show()

print(f"True p = {p_true}, observed k = {k}/{n}, MLE p̂ = {p_mle:.4f}")
print(f"ℓ(p̂) = {log_lik(p_mle):.3f}, ℓ(p_true) = {log_lik(p_true):.3f}")
← Previous
Week 7: Laws of Large Numbers and the CLT
Next →
Week 9: Bayesian Estimation and MAP
On this page
  • Estimators as Functions of Data
  • Likelihood
  • Bernoulli MLE
  • Gaussian MLE
  • MLE and Training Objectives
  • Knowledge check
  • Browser lab