Master the three numbers that summarize any distribution: mean, variance, and standard deviation. Derive linearity of expectation, understand covariance and correlation, then see why the Central Limit Theorem makes the Gaussian unavoidable — with a worked numeric example from scratch.
Not signed in — your progress and quiz score won't be saved.
Lesson progress1 / 10
Expected value: the distribution's center of mass
The expected value (mean) of X is its probability-weighted average:
E[X]=⎩⎨⎧x∑xp(x)∫−∞∞xf(x)dxdiscretecontinuous
Think of it as the center of mass of the PMF/PDF. It need not be a likely value — for a fair die, E[X]=3.5, which never appears on a roll.
Expected value of a function: E[g(X)]=∑xg(x)p(x). This is the law of the unconscious statistician (LOTUS) — you integrate g(x) against the original distribution of X, no change of variables needed.
Full lesson text
All 10 steps on one page — for reading, reference, and search.
ShowHide
1. Expected value: the distribution's center of mass
The expected value (mean) of X is its probability-weighted average:
E[X]=⎩⎨⎧x∑xp(x)∫−∞∞xf(x)dxdiscretecontinuous
Think of it as the center of mass of the PMF/PDF. It need not be a likely value — for a fair die, E[X]=3.5, which never appears on a roll.
Expected value of a function: E[g(X)]=∑xg(x)p(x). This is the law of the unconscious statistician (LOTUS) — you integrate g(x) against the original distribution of X, no change of variables needed.
2. Linearity of expectation
The single most useful fact in probability:
E[aX+bY+c]=aE[X]+bE[Y]+c
This holds regardless of whether X and Y are independent. No joint distribution needed.
Example: what is the expected number of fixed points (cards in their natural position) in a random shuffle of n cards? Define Xi=1[card i is fixed]. Then E[Xi]=1/n and
E[∑i=1nXi]=∑i=1nE[Xi]=n⋅n1=1.
Always exactly 1, for any n — a clean result that would be a combinatorial nightmare without linearity.
3. Variance and standard deviation
Variance measures spread around the mean:
Var(X)=E[(X−E[X])2]=E[X2]−(E[X])2.
The second form — raw second moment minus squared mean — is almost always faster to compute. The standard deviation is σ=Var(X), which lives in the same units as X.
Key scaling rules:
Var(aX+b)=a2Var(X) — shift has no effect, scale is squared.
If X,Y independent: Var(X+Y)=Var(X)+Var(Y).
If dependent: Var(X+Y)=Var(X)+Var(Y)+2Cov(X,Y).
Variance is not linear — a common source of errors in error-propagation and mini-batch gradient analysis.
4. Worked example: rolling two dice
Let X and Y be independent fair dice (1–6). Compute E[X+Y] and Var(X+Y).
Step 1. For one fair die: E[X]=61(1+2+3+4+5+6)=3.5.
Step 2.E[X2]=61(1+4+9+16+25+36)=691≈15.17.
Step 3.Var(X)=15.17−3.52=15.17−12.25=2.92.
Step 4. By linearity: E[X+Y]=3.5+3.5=7.
Step 5. By independence: Var(X+Y)=2.92+2.92=5.83, so σX+Y=5.83≈2.42.
ρ=1: perfect positive linear relationship; ρ=0: uncorrelated (but not necessarily independent); ρ=−1: perfect negative.
For a random vector X∈Rd, the covariance matrixΣij=Cov(Xi,Xj) is symmetric and positive semi-definite — it appears in Gaussian distributions, PCA, and Kalman filters.
6. The Law of Large Numbers
Let X1,X2,… be i.i.d. with mean μ and finite variance σ2. The sample mean is Xˉn=n1∑i=1nXi.
Weak LLN: For any ε>0, P(∣Xˉn−μ∣>ε)→0 as n→∞.
Proof sketch via Chebyshev: P(∣Xˉn−μ∣>ε)≤ε2Var(Xˉn)=nε2σ2→0.
In ML: Monte Carlo estimators, stochastic gradient descent, empirical risk minimization — all implicitly rely on the LLN. When you average enough noisy gradient estimates, you get close to the true gradient. The LLN tells you convergence happens; the CLT tells you how fast and what the fluctuations look like.
7. The Central Limit Theorem
The most important theorem in statistics:
CLT. If X1,…,Xn are i.i.d. with mean μ and variance σ2<∞, then
σ/nXˉn−μdN(0,1)as n→∞.
Three takeaways:
The shape of the original distribution is irrelevant — the sum converges to Gaussian.
The fluctuations shrink as 1/n, not 1/n. Halving the error requires 4× the data.
The approximation is often usable by n≈30 for unimodal distributions, but may need n≫100 for heavy-tailed ones.
This is why Gaussian noise appears in so many models: real noise is typically a sum of many small independent perturbations.
8. Standard error and confidence in practice
The standard error of the mean (SEM) is the standard deviation of Xˉn:
SE=nσ.
In practice σ is unknown, so you substitute the sample standard deviation s=n−11∑i(Xi−Xˉ)2.
The SEM quantifies estimation uncertainty. A rough 95% interval for μ is Xˉn±1.96⋅SE (via the CLT). Comparing two models? Compute the SEM of the accuracy difference — if the interval excludes 0, the difference is statistically detectable at the 5% level.
import numpy as np
from scipy import stats
np.random.seed(42)
data = np.random.exponential(scale=5, size=200) # non-Gaussian!
xbar = data.mean()
se = stats.sem(data)
ci = stats.t.interval(0.95, df=len(data)-1, loc=xbar, scale=se)
print(f"mean={xbar:.2f}, SE={se:.2f}, 95% CI={ci}")
Notice we used a t-distribution (not normal) because n=200 with unknown σ — conservative and correct.
9. From i.i.d. samples to the CLT
How repeated averaging turns any distribution into a Gaussian:
flowchart LR
A["i.i.d. samples X1...Xn from any distribution"]
B["Sample mean Xbar_n = (1/n) sum Xi"]
C["E[Xbar_n] = mu, Var(Xbar_n) = sigma^2 / n"]
D["Standardize: Z_n = (Xbar_n - mu) / (sigma / sqrt(n))"]
E["CLT: Z_n -> N(0,1) as n -> infinity"]
F["Confidence intervals and hypothesis tests"]
A --> B
B --> C
C --> D
D --> E
E --> F
10. Why Gaussians are everywhere in ML
Beyond the CLT, Gaussians dominate ML for three deeper reasons:
Maximum entropy. Among all distributions with fixed mean μ and variance σ2, N(μ,σ2) has the highest differential entropy. It's the "most uncertain" distribution given those two constraints — a natural prior when you know only the first two moments.
Analytic tractability. Gaussians are closed under linear transformations, conditioning, and marginalization. If (X,Y) is jointly Gaussian, X∣Y=y is Gaussian with a closed-form mean and variance. This is the engine of Gaussian processes and Kalman filters.
Exponential family.N(μ,σ2) is in the exponential family, making maximum-likelihood estimation and Bayesian conjugacy computationally clean.
Every time you assume "Gaussian noise," you're implicitly invoking the CLT, maximum entropy, and analytic convenience simultaneously.
Check your understanding
The lesson ends with a 5-question quiz. Take it in the player above to see your score.
Let $X$ be a discrete RV with $P(X=-1) = 0.5$ and $P(X=3) = 0.5$. What is $\text{Var}(X)$?
4
2
8
1
You have i.i.d. samples $X_1, \ldots, X_{100}$ with $\mathbb{E}[X]=2$ and $\text{Var}(X)=9$. What is the standard error of $\bar{X}_{100}$?
0.09
0.3
0.9
3
Which statement about linearity of expectation is correct?
The CLT says that $\bar{X}_n$ converges to a Gaussian as $n \to \infty$. Which is the correct rate of convergence of the standard deviation of $\bar{X}_n$?
It shrinks at rate $1/n$.
It shrinks at rate $1/\sqrt{n}$.
It shrinks at rate $1/\log n$.
It shrinks at rate $1/n^2$.
Two RVs $X$ and $Y$ have $\text{Cov}(X, Y) = 0$. What can you conclude?
$X$ and $Y$ are independent.
$X$ and $Y$ are uncorrelated, but may still be dependent.