[MMD]
ML Probability & Statistics Chapter 3: Sampling, MLE, and MAP
In Chapter 2 we covered descriptive statistics and multivariate distributions. This post focuses on estimating a population from samples, along with the two workhorses of machine learning estimation: MLE and MAP.
This post is based on Week 2 of DeepLearning.AI's Mathematics for Machine Learning and Data Science — Probability & Statistics.
What You'll Learn#
- Population vs. Sample — what they are and why the distinction matters
- Sample mean, proportion, and variance — unbiased estimators
- Law of Large Numbers — why more data means better estimates
- Central Limit Theorem (CLT) — why any distribution converges to normal with enough samples
- MLE — finding the parameters that best explain your data
- MAP — combining MLE with prior information
- Regularization — the connection between MAP and L2 regularization
Population and Sample#
Key Concepts#
| Term | Definition |
|---|---|
| Population | The complete set of subjects under study |
| Sample | A randomly drawn subset of the population |
| Parameter | A characteristic of the population (, ) |
| Statistic | An estimate computed from the sample (, ) |
Why use samples? Measuring an entire population is often impossible or prohibitively expensive, so we use random samples to infer population characteristics.
Properties of a good sample (i.i.d.):
- Independence: each observation does not influence the others
- Identical distribution: all observations are drawn from the same distribution
Sample Mean#
- An unbiased estimator of the population mean
- As the sample size grows,
Sample Variance#
Why ? (Bessel's Correction): Dividing by underestimates the population variance. Because one degree of freedom is consumed when estimating the mean, dividing by yields an unbiased estimator.
The MLE variance estimator uses and is therefore biased. In practice, always use for sample variance.
Law of Large Numbers#
As the sample size grows, the sample mean converges to the population mean.
Example: When flipping a coin, the proportion of heads fluctuates wildly in the first few tosses (0.3, 0.7, …), but converges to 0.5 after thousands of trials.
ML implication: The more training data you have, the better your model can learn the true data distribution.
Central Limit Theorem (CLT)#
The Core Statement#
Regardless of the original distribution's shape, the sample mean of independent, identically distributed random variables converges to a normal distribution as grows large.
Standardized form:
Key Points#
| Item | Value |
|---|---|
| Minimum sample size for CLT | Typically |
| If the original distribution is symmetric | Converges with smaller |
| If the original distribution is skewed | Requires larger |
Why standardize?: The variance of the sample mean is , which changes with , making direct comparisons difficult.
Practical significance: No matter what distribution your data comes from, statistics computed from a sufficiently large sample follow a normal distribution. This is the theoretical foundation of confidence intervals and hypothesis testing.
Maximum Likelihood Estimation (MLE)#
Core Idea#
Find the parameters most likely to have generated the observed data.
We find the that maximizes the likelihood of the observed data.
Bernoulli MLE Example#
Flip a coin 10 times, observe 8 heads:
Apply the log transformation (products → sums):
Differentiate and set to zero:
Takeaway: The MLE estimate equals the observed frequency — an intuitively satisfying result.
Gaussian MLE#
Given samples drawn from :
MLE for the mean:
MLE for the variance:
The MLE variance estimator uses and is biased (the sample variance uses and is unbiased).
Linear Regression and MLE#
For linear regression (where ):
Maximizing the likelihood with respect to and is equivalent to:
Takeaway: Under a normality assumption, MLE = Ordinary Least Squares.
Regularization#
The Overfitting Problem#
When a model is too complex, it overfits the training data and performs poorly on new data.
Solution: Add a penalty term for complexity.
L2 Regularization (Ridge):
- Larger coefficients incur larger penalties
- Shrinks all coefficients toward zero (but never exactly to zero)
L1 Regularization (Lasso): Sum of absolute values of coefficients → drives some coefficients to exactly zero, enabling feature selection.
Hyperparameter : Controls the penalty strength. A larger produces a simpler model; a smaller stays closer to the unregularized model.
MAP and Bayesian Statistics#
Frequentist vs. Bayesian#
| Frequentist | Bayesian | |
|---|---|---|
| View of parameters | Fixed but unknown values | Random variables with uncertainty |
| Estimation method | MLE | Prior + data → posterior |
| Output | Point estimate | Distribution |
MAP (Maximum A Posteriori)#
MLE + Prior information:
- Uniform prior → MAP = MLE
- Informative prior → prior knowledge is incorporated into the estimate
Connection Between MAP and L2 Regularization#
Assume a Gaussian prior on :
Maximizing MAP = minimizing the MLE loss + a penalty
Conclusion: L2 regularization = MAP estimation with a Gaussian prior.
Updating the Prior (Prior → Posterior)#
The heart of Bayesian statistics: update the prior each time new data is observed.
Sequential updating: the previous posterior becomes the next prior.
Whether you process data all at once or sequentially, the final posterior is the same.
MAP choice: Use the mode of the posterior distribution as a point estimate.
MLE vs. MAP Summary#
| MLE | MAP | |
|---|---|---|
| Uses prior information | ❌ | ✅ |
| Equivalent to | Least Squares | L2/L1 Regularization |
| With little data | Risk of overfitting | Stabilized by prior |
| With lots of data | MLE ≈ MAP | Prior influence diminishes |
| Output | Point estimate | Point estimate (mode of posterior) |
Key Takeaways#
| Concept | Summary |
|---|---|
| Population/Sample | Whole/subset; i.i.d. condition |
| Sample variance | Unbiased with |
| Law of Large Numbers | → sample mean → population mean |
| Central Limit Theorem | → sample mean ~ normal distribution |
| MLE | Maximize likelihood = observed frequency / least squares |
| MAP | Maximize likelihood × prior = MLE + regularization |
| L2 Regularization | Equivalent to MAP with a Gaussian prior |
Quiz#
Q1. Why do we divide by instead of when computing sample variance?
Show answer
Bessel's Correction: Estimating the mean from the sample consumes one degree of freedom.
Dividing by underestimates the population variance. Dividing by removes this bias and yields an unbiased estimator.
Intuition: data points within a sample tend to cluster around the sample mean, making the spread appear smaller than it really is in the full population.
Q2. Which of the following statements about the Central Limit Theorem is correct?
- The original distribution must be normal
- When the sample size is large, the distribution of the sample mean approaches a normal distribution
- As the sample size increases, the population variance decreases
- The sample mean always equals the population mean
Show answer
Answer: 2
- 1 ❌: CLT applies regardless of the original distribution's shape
- 2 ✅: This is the core statement of the CLT
- 3 ❌: The sample mean's variance shrinks to ; the population variance itself does not change
- 4 ❌: The sample mean converges probabilistically to the population mean, but they are not always equal
Q3. You flip a coin 10 times and observe 7 heads. What is the MLE estimate of the probability of heads?
Show answer
The MLE estimate equals the observed frequency.
Q4. Explain the difference between MLE and MAP, and describe the connection to L2 regularization.
Show answer
- MLE: maximizes the likelihood using data alone
- MAP: also incorporates a prior by maximizing
Assuming a Gaussian prior on :
This is exactly the form of L2 regularization (Ridge).
→ L2 regularization = MAP estimation with a Gaussian prior
Q5. Which of the following correctly describes the difference between the Law of Large Numbers and the Central Limit Theorem?
- The LLN describes the shape of the sample mean's distribution; the CLT describes the rate of convergence
- The LLN states that the sample mean converges to the population mean; the CLT states that the distribution of the sample mean converges to a normal distribution
- The LLN applies only to continuous variables; the CLT applies only to discrete variables
Show answer
Answer: 2
- Law of Large Numbers: as , — the value of the sample mean approaches the population mean
- CLT: for large , the distribution of approaches
The two theorems describe different aspects: the LLN addresses convergence of the value, while the CLT describes the shape of the distribution it converges to.
The next post will cover Confidence Intervals and Hypothesis Testing — methods for quantifying the uncertainty in our estimates.
// Related Posts
Probability & Statistics in Practice: Inference Problems from the ML Trenches
From probability fundamentals and Bayes' theorem to distributions, MLE/MAP, confidence intervals, and hypothesis testing — a collection of practice problems grounded in real ML and data analysis scenarios.
Probability & Statistics Coding Assignments: Building ML Statistical Tools in Python
Bayesian updates, distribution simulation, CLT verification, MLE/MAP implementation, confidence intervals, hypothesis testing, and a full A/B test pipeline — implementing probability & statistics chapters 1–4 in code.
ML Probability & Statistics Chapter 4: Confidence Intervals and Hypothesis Testing
A complete guide to confidence intervals, the t-distribution, hypothesis testing fundamentals (null/alternative hypotheses, p-values, rejection regions, statistical power), various t-tests, and A/B testing.