Skip to main content
© 2026 ePowerAI. All rights reserved.
CoursesContact
eAI
CoursesContact
Week 10: Bias, Variance, and Uncertainty
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 10· Prob & Stats· Inference22 min read

Week 10: Bias, Variance, and Uncertainty

✦Learning Outcomes
  • Define bias, variance, and MSE of an estimator
  • Explain bias–variance tradeoff in estimation and model complexity stories
  • Interpret a basic interval for a mean (CLT-based) without p-value machinery
  • Describe the bootstrap algorithm for a statistic's sampling distribution
◆Prerequisites

Required: Weeks 7–9 (LLN/CLT, MLE, MAP/Bayesian estimation). Week 3 (expectation and variance).

Note: This week teaches how to judge an estimator's quality, not how to test hypotheses. We introduce confidence intervals lite to quantify uncertainty — no Neyman–Pearson lemma, p-values, or ANOVA.

Bias and Variance#

Every estimator θ^\hat \thetaθ^ is a random variable (it depends on the random sample). How do we judge whether an estimator is "good"? Two orthogonal qualities:

  • Bias: Bias(θ^)=E[θ^]−θ\text{Bias}(\hat \theta) = \mathbb{E}[\hat \theta] - \thetaBias(θ^)=E[θ^]−θ. Does the estimator systematically over- or under-shoot the truth on average?
  • Variance: Var(θ^)\mathrm{Var}(\hat \theta)Var(θ^). How much does the estimate jump around from sample to sample?

Mean Squared Error (MSE) combines both:

MSE(θ^)=E[(θ^−θ)2]=Bias(θ^)2+Var(θ^).\text{MSE}(\hat \theta) = \mathbb{E}[(\hat \theta - \theta)^2] = \text{Bias}(\hat \theta)^2 + \mathrm{Var}(\hat \theta).MSE(θ^)=E[(θ^−θ)2]=Bias(θ^)2+Var(θ^).

Proof: Add and subtract E[θ^]\mathbb{E}[\hat \theta]E[θ^]:

E[(θ^−θ)2]=E[(θ^−E[θ^]+E[θ^]−θ)2]=E[(θ^−E[θ^])2]+(E[θ^]−θ)2+0=Var(θ^)+Bias(θ^)2.\mathbb{E}[(\hat \theta - \theta)^2] = \mathbb{E}[(\hat \theta - \mathbb{E}[\hat \theta] + \mathbb{E}[\hat \theta] - \theta)^2] \\ = \mathbb{E}[(\hat \theta - \mathbb{E}[\hat \theta])^2] + (\mathbb{E}[\hat \theta] - \theta)^2 + 0 = \mathrm{Var}(\hat \theta) + \text{Bias}(\hat \theta)^2.E[(θ^−θ)2]=E[(θ^−E[θ^]+E[θ^]−θ)2]=E[(θ^−E[θ^])2]+(E[θ^]−θ)2+0=Var(θ^)+Bias(θ^)2.

The cross-term vanishes because E[θ^−E[θ^]]=0\mathbb{E}[\hat \theta - \mathbb{E}[\hat \theta]] = 0E[θ^−E[θ^]]=0.

This is the bias–variance decomposition: to reduce MSE, you can reduce bias or reduce variance. But estimators that reduce one often increase the other — the bias–variance tradeoff.

Estimator terminology:

  • Unbiased: E[θ^]=θ\mathbb{E}[\hat \theta] = \thetaE[θ^]=θ (bias = 0).
  • Consistent: θ^→pθ\hat \theta \xrightarrow{p} \thetaθ^p​θ as n→∞n \to \inftyn→∞ (MSE → 0).
  • Efficient: achieves the smallest possible variance among a class (e.g., among unbiased estimators).

Worked Estimators — Sample Variance#

The most famous bias–variance story. Given i.i.d. Xi∼N(μ,σ2)X_i \sim \mathcal{N}(\mu, \sigma^2)Xi​∼N(μ,σ2):

  • MLE (denominator nnn): σ^MLE2=1n∑(Xi−Xˉ)2\hat \sigma^2_{\text{MLE}} = \frac{1}{n}\sum (X_i - \bar X)^2σ^MLE2​=n1​∑(Xi​−Xˉ)2.
  • Unbiased (denominator n−1n-1n−1): S2=1n−1∑(Xi−Xˉ)2S^2 = \frac{1}{n-1}\sum (X_i - \bar X)^2S2=n−11​∑(Xi​−Xˉ)2.

E[σ^MLE2]=n−1nσ2<σ2\mathbb{E}[\hat \sigma^2_{\text{MLE}}] = \frac{n-1}{n}\sigma^2 < \sigma^2E[σ^MLE2​]=nn−1​σ2<σ2 — biased downward. E[S2]=σ2\mathbb{E}[S^2] = \sigma^2E[S2]=σ2 — unbiased.

Why n−1n-1n−1? The sample mean Xˉ\bar XXˉ is the value that minimises the sum of squared deviations. This "uses up" one degree of freedom, making the sum slightly too small on average. Dividing by n−1n-1n−1 corrects for this.

For large nnn, the difference is negligible. For small samples, the unbiased estimator has larger variance (its MSE can actually be higher than the biased MLE — the bias–variance tradeoff in action).

Confidence Interval (lite)#

A confidence interval gives a range of plausible values for θ\thetaθ, calibrated by the sampling distribution of the estimator.

For the mean (CLT-based, large nnn): By the CLT, Xˉn≈N(μ,σ2/n)\bar X_n \approx \mathcal{N}(\mu, \sigma^2 / n)Xˉn​≈N(μ,σ2/n). Standardising:

P ⁣(−zα/2≤Xˉn−μσ/n≤zα/2)≈1−α.P\!\left(-z_{\alpha/2} \le \frac{\bar X_n - \mu}{\sigma / \sqrt{n}} \le z_{\alpha/2}\right) \approx 1 - \alpha.P(−zα/2​≤σ/n​Xˉn​−μ​≤zα/2​)≈1−α.

Rearranging gives the 100(1−α)%100(1-\alpha)\%100(1−α)% confidence interval:

Xˉn±zα/2⋅σn.\bar X_n \pm z_{\alpha/2} \cdot \frac{\sigma}{\sqrt{n}}.Xˉn​±zα/2​⋅n​σ​.

For a 95% CI, z0.025≈1.96z_{0.025} \approx 1.96z0.025​≈1.96. In practice, σ\sigmaσ is unknown and replaced by the sample standard deviation sss, which adds uncertainty; for large nnn this is fine, for small nnn use the ttt-distribution (not covered here).

Critical interpretation — what a CI is NOT:

A 95% CI does not mean "there is a 95% probability that μ\muμ lies in this interval." μ\muμ is a fixed constant (in the frequentist view). The correct interpretation: if we repeated the experiment many times and computed a 95% CI each time, approximately 95% of those intervals would contain the true μ\muμ. The procedure works 95% of the time.

This is a subtle but important distinction from the Bayesian credible interval, where you can say "the probability that μ\muμ is in this interval is 95%," because μ\muμ is treated as a random variable with a posterior distribution.

Worked example. n=100n = 100n=100 observations, xˉ=52.3\bar x = 52.3xˉ=52.3, s=8.0s = 8.0s=8.0. A 95% CI for μ\muμ:

52.3±1.96⋅8.0100=52.3±1.568=[50.73,53.87].52.3 \pm 1.96 \cdot \frac{8.0}{\sqrt{100}} = 52.3 \pm 1.568 = [50.73, 53.87].52.3±1.96⋅100​8.0​=52.3±1.568=[50.73,53.87].

Bootstrap#

The bootstrap is a computational method to estimate the sampling distribution of any statistic without assuming a parametric model. It replaces theory with computation.

Algorithm (nonparametric bootstrap):

  1. From the original sample x1,…,xnx_1, \ldots, x_nx1​,…,xn​, draw a bootstrap sample x1∗,…,xn∗x_1^*, \ldots, x_n^*x1∗​,…,xn∗​ by sampling nnn times with replacement from the original data.
  2. Compute the statistic of interest θ^∗=g(x1∗,…,xn∗)\hat \theta^* = g(x_1^*, \ldots, x_n^*)θ^∗=g(x1∗​,…,xn∗​) on the bootstrap sample.
  3. Repeat steps 1–2 BBB times (typically B=1000B = 1000B=1000 or more) to get θ^1∗,…,θ^B∗\hat \theta_1^*, \ldots, \hat \theta_B^*θ^1∗​,…,θ^B∗​.
  4. The empirical distribution of the θ^b∗\hat \theta_b^*θ^b∗​ approximates the sampling distribution of θ^\hat \thetaθ^.

What the bootstrap gives you:

  • Standard error: SEboot=std(θ^1∗,…,θ^B∗)\text{SE}_{\text{boot}} = \text{std}(\hat \theta_1^*, \ldots, \hat \theta_B^*)SEboot​=std(θ^1∗​,…,θ^B∗​).
  • Confidence interval (percentile): the (α/2)(\alpha/2)(α/2) and (1−α/2)(1-\alpha/2)(1−α/2) quantiles of the bootstrap distribution.
  • Bias estimate: E∗[θ^∗]−θ^\mathbb{E}^*[\hat \theta^*] - \hat \thetaE∗[θ^∗]−θ^ (mean of bootstrap estimates minus original estimate).

The bootstrap works when: the empirical distribution of the sample is a good approximation of the true population distribution. It is especially useful when no closed-form formula for the standard error exists (e.g., median, correlation coefficient, or a complex model output).

When bootstrap fails: dependent data (need block bootstrap), heavy tails (need subsampling bootstrap), small nnn (empirical distribution is too coarse).

What We Are Not Doing#

This course deliberately limits classical statistics to what supports ML practice:

  • No Neyman–Pearson hypothesis testing (null vs alternative, rejection regions, p-values, Type I/II errors).
  • No multiple testing corrections (Bonferroni, FDR).
  • No ANOVA or experimental design.
  • No power analysis.

These are important topics in classical applied statistics, but they are not prerequisites for understanding MLE, KL divergence, or probabilistic generative models — which is what this course targets.

Exercise · Multiple choice

As sample size n increases, which component of MSE typically shrinks?

Variance
Bias²
Both equally
Neither — MSE is constant

Knowledge check#

Question 1 of 4

An estimator has bias 0.2 and variance 0.09. What is its MSE?


Browser lab#

Bootstrap the sampling distribution of the sample mean and compare the bootstrap SE to the CLT formula.

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

rng = np.random.default_rng(42)

true_mu, true_sigma = 50.0, 10.0
n = 30
data = rng.normal(true_mu, true_sigma, size=n)

B = 2000
boot_means = np.empty(B)
for b in range(B):
    boot_sample = rng.choice(data, size=n, replace=True)
    boot_means[b] = boot_sample.mean()

se_boot = boot_means.std()
se_clt = data.std(ddof=1) / np.sqrt(n)

ci_lower = np.percentile(boot_means, 2.5)
ci_upper = np.percentile(boot_means, 97.5)

fig, axes = plt.subplots(1, 2, figsize=(12, 4.5))

axes[0].hist(boot_means, bins=40, density=True, alpha=0.7, color="tab:blue")
axes[0].axvline(data.mean(), color="tab:red", linewidth=2, label=f"Sample mean = {data.mean():.2f}")
axes[0].axvline(ci_lower, color="black", linestyle="--", linewidth=1)
axes[0].axvline(ci_upper, color="black", linestyle="--", linewidth=1, label=f"95% CI: [{ci_lower:.2f}, {ci_upper:.2f}]")
axes[0].set_title("Bootstrap distribution of the mean")
axes[0].set_xlabel("Mean"); axes[0].legend()

x_grid = np.linspace(boot_means.min(), boot_means.max(), 200)
normal_approx = (1/(np.sqrt(2*np.pi)*se_clt)) * np.exp(-0.5*((x_grid - data.mean())/se_clt)**2)
axes[1].hist(boot_means, bins=40, density=True, alpha=0.5, label="Bootstrap")
axes[1].plot(x_grid, normal_approx, "tab:red", linewidth=2, label=f"CLT approx (SE={se_clt:.2f})")
axes[1].set_title("Bootstrap vs CLT normal approximation")
axes[1].set_xlabel("Mean"); axes[1].legend()

plt.tight_layout()
plt.show()

print(f"Sample: n={n}, mean={data.mean():.3f}, std={data.std(ddof=1):.3f}")
print(f"SE (CLT):  {se_clt:.4f}")
print(f"SE (boot): {se_boot:.4f}")
print(f"95% CI (boot): [{ci_lower:.3f}, {ci_upper:.3f}]")
print(f"95% CI (CLT):  [{data.mean()-1.96*se_clt:.3f}, {data.mean()+1.96*se_clt:.3f}]")
← Previous
Week 9: Bayesian Estimation and MAP
Next →
Week 11: Information Theory for ML
On this page
  • Bias and Variance
  • Worked Estimators — Sample Variance
  • Confidence Interval (lite)
  • Bootstrap
  • What We Are Not Doing
  • Knowledge check
  • Browser lab