Guide To AI Logo
Unit 11

Statistics for Machine Learning

analyzing data, estimating patterns, and understanding uncertainty in machine learning models

Core Concepts Covered

  • Descriptive vs. inferential statistics
  • Hypothesis testing, confidence intervals, and significance testing
  • Maximum Likelihood Estimation (MLE) and parameter estimation

1. Descriptive vs. Inferential Statistics (Bessel's Correction)

Statistics provides the mathematical framework to summarize datasets, detect hidden patterns, and draw conclusions under uncertainty. It is broadly divided into two domains:

Descriptive Statistics: Summarizes the numerical properties of an observed sample (such as the sample mean xˉ=1nxi\bar{x} = \frac{1}{n} \sum x_i and sample variance s2s^2).

Why Bessel's Correction (n1n-1) is Crucial: When computing sample variance, we divide by n1n-1 rather than nn:

s2=1n1i=1n(xixˉ)2s^2 = \frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})^2

Dividing by nn underestimates the true population variance because the sample data points are naturally closer to their own sample mean xˉ\bar{x} than they are to the true, unobserved population mean μ\mu. Dividing by n1n-1 (Bessel's Correction) mathematically corrects this bias, providing an unbiased estimator of the population variance.

Inferential Statistics: Uses sample data to make generalized predictions, test claims, or draw conclusions about a larger, unobserved population.

Samples Produce a Distribution of Estimates

sample means cluster around μ
Read diagram labels
  • sample means cluster around μ
Worked Example 1

Sample Summaries with Bessel's Correction

Problem

For the sample (2,4,4,6)(2,4,4,6), find the mean, median, range, and sample variance.

Step-by-step solution

1.xˉ=(2+4+4+6)/4=4\bar x=(2+4+4+6)/4=4; the median is 44 and range is 62=46-2=4.

2.Squared deviations are 4,0,0,44,0,0,4, summing to 88.

Final answer and interpretation

s2=8/(41)=8/32.67s^2=8/(4-1)=8/3\approx2.67; the sample standard deviation is 8/31.63\sqrt{8/3}\approx1.63.

Only three deviations are free after the sample mean has been estimated, motivating the n1n-1 denominator.

2. Hypothesis Testing, p-values, and A/B Testing

In machine learning, we use hypothesis testing to determine if our model improvements are statistically genuine or merely the result of random noise.

The A/B Test Example: Suppose your baseline model (A) has an accuracy of 80%80\%. You develop a new model (B) and test it on a sample of 100100 users, achieving an accuracy of 83%83\%. Is this 3%3\% improvement genuine, or did you just get lucky with a favorable sample of users? We resolve this using hypothesis testing:

Null Hypothesis (H0H_0): The default assumption that there is no real difference or effect (e.g., 'Model B has the same performance as Model A; the 3%3\% difference is random noise').

Alternative Hypothesis (HaH_a): The claim we want to prove (e.g., 'Model B is genuinely superior to Model A').

Significance Level (α\alpha): The threshold of risk we are willing to accept (typically set to 0.050.05 or 5%5\%). It is the probability of rejecting H0H_0 when it is actually true (Type I error).

The pp-value: Assuming H0H_0 is true, this is the probability of a result at least as incompatible with H0H_0 as the observed one. It is not the probability that H0H_0 is true and does not measure effect size. A small value supplies evidence against H0H_0 under the model assumptions.

Confidence Intervals (CI): A range of values likely to contain the true population parameter with a specified confidence level (e.g., 95%95\% confidence interval: xˉ±zsn\bar{x} \pm z^* \frac{s}{\sqrt{n}}).

Rejection Regions and Test Errors

reject H₀reject H₀
Read diagram labels
  • reject H₀
Worked Example 1

Confidence Interval and One-Sample Test

Problem

A sample of n=100n=100 model latencies has mean 4848 ms and known standard deviation 1010 ms. Form a 95%95\% CI and test H0:μ=50H_0:\mu=50 against a two-sided alternative.

Step-by-step solution

1.Standard error is 10/100=110/\sqrt{100}=1 ms.

2.The CI is 48±1.96(1)=(46.04,49.96)48\pm1.96(1)=(46.04,49.96) ms.

Final answer and interpretation

z=(4850)/1=2z=(48-50)/1=-2, giving a two-sided p0.0455p\approx0.0455; reject at α=0.05\alpha=0.05.

Statistical significance here is borderline; practical importance still depends on whether a 2 ms change matters.

Worked Example 2

Type I, Type II, and Power

Problem

An A/B test uses α=0.05\alpha=0.05 and has power 0.800.80 for a meaningful lift. Interpret both numbers.

Step-by-step solution

1.If there is truly no lift, the procedure falsely declares one in 5%5\% of repeated experiments: Type I error.

2.If the specified meaningful lift is real, it detects it in 80%80\% of repeated experiments.

Final answer and interpretation

The corresponding Type II error probability at that effect size is β=10.80=0.20\beta=1-0.80=0.20.

3. Parameter Estimation & Maximum Likelihood (MLE)

Machine learning is essentially the search for optimal parameters. We find these parameters using parameter estimation frameworks, most notably Maximum Likelihood Estimation (MLE).

The goal of MLE is to find the parameter values θ\theta that maximize the likelihood of observing our actual dataset DD. Assuming samples are independent and identically distributed (i.i.d.), the joint likelihood is the product of individual sample probabilities: L(θ)=i=1nP(xiθ)L(\theta) = \prod_{i=1}^n P(x_i | \theta)

Because multiplying probabilities causes numerical underflow, we maximize the log-likelihood function instead: lnL(θ)=i=1nlnP(xiθ)\ln L(\theta) = \sum_{i=1}^n \ln P(x_i | \theta)

The Coin-Flip Derivation: If we flip a coin nn times and observe kk heads (successes), we model this using a Bernoulli distribution with success parameter θ\theta. The likelihood function is: L(θ)=θk(1θ)nkL(\theta) = \theta^k (1 - \theta)^{n-k} Taking the natural log converts the exponent multiplication into addition: lnL(θ)=kln(θ)+(nk)ln(1θ)\ln L(\theta) = k \ln(\theta) + (n-k) \ln(1 - \theta) To find the parameter value that maximizes this log-likelihood, we take the derivative with respect to θ\theta, set it to 0, and solve: ddθlnL(θ)=kθnk1θ=0\frac{d}{d\theta} \ln L(\theta) = \frac{k}{\theta} - \frac{n-k}{1-\theta} = 0 kθ=nk1θ    k(1θ)=θ(nk)\frac{k}{\theta} = \frac{n-k}{1-\theta} \implies k(1-\theta) = \theta(n-k) kkθ=nθkθ    θMLE=knk - k\theta = n\theta - k\theta \implies \theta_{\text{MLE}} = \frac{k}{n} This proves mathematically that our intuitive estimate, the proportion of observed heads, is the mathematically optimal parameter maximizing the likelihood of our observations!

Likelihood Peaks at the Maximum-Likelihood Estimate

θ̂MLE = k/nL(θ)
Read diagram labels
  • θ̂MLE = k/n
  • L(θ)
Worked Example 1

Numerical Bernoulli MLE

Problem

A classifier is correct on 7 of 10 independent cases. Estimate its Bernoulli success parameter and compare log-likelihoods at θ=0.7\theta=0.7 and 0.50.5.

Step-by-step solution

1.The MLE is θ^=k/n=7/10=0.7\hat\theta=k/n=7/10=0.7.

2.(0.7)=7ln0.7+3ln0.36.109\ell(0.7)=7\ln0.7+3\ln0.3\approx-6.109.

Final answer and interpretation

(0.5)=10ln0.56.931\ell(0.5)=10\ln0.5\approx-6.931; the larger value at 0.70.7 better explains the observations.

MLE chooses the parameter that makes the observed data most likely; it does not claim the estimate is error-free.

Worked Example 2

Cumulative A/B Effect Estimate

Problem

Variant A converts 40/20040/200 users and B converts 54/20054/200. Compute the observed absolute and relative lifts.

Step-by-step solution

1.p^A=0.20\hat p_A=0.20 and p^B=0.27\hat p_B=0.27.

2.Absolute lift is 0.270.20=0.070.27-0.20=0.07, or 7 percentage points.

Final answer and interpretation

Relative lift is 0.07/0.20=35%0.07/0.20=35\%. A hypothesis test or interval is still required to quantify uncertainty.

Interactive Practice Quiz

Test your understanding with instant feedback

QUESTION 01

Why do we divide by n1n-1 instead of nn when calculating the Sample Variance s2s^2?

QUESTION 02

If a hypothesis test yields a pp-value of 0.010.01 and we set our significance level α=0.05\alpha = 0.05, what is our conclusion?

QUESTION 03

Which of the following describes the objective of Maximum Likelihood Estimation (MLE)?

QUESTION 04

Why do we maximize the 'Log-Likelihood' instead of the raw 'Likelihood' function in MLE?

QUESTION 05

In a coin-flip experiment with a Bernoulli distribution, if you observe 12 heads in 20 trials, what is the MLE value of the success probability parameter θ\theta?

QUESTION 06

Which of the following describes the difference between Descriptive and Inferential Statistics?

QUESTION 07

In hypothesis testing, what is a 'Type I Error'?

QUESTION 08

In hypothesis testing, what does a 'Type II Error' represent?

QUESTION 09

What is the correct interpretation of a '95% Confidence Interval' for a population mean?

QUESTION 10

If we observe kk successes in nn independent Bernoulli trials, what is the log-likelihood function lnL(θ)\ln L(\theta) for the success parameter θ\theta?