Expectation and Variance
Formal
(Expectation)
The expectation (mean) of a random variable is its probability-weighted average value:
Key property — Linearity of Expectation: for any RVs and scalars :
This holds even when and are dependent. It is one of the most powerful and frequently used results in probability.
(Variance)
The variance measures how spread out is around its mean :
The standard deviation is in the same units as .
Key properties:
For independent : .
(Law of the Unconscious Statistician)
For any function :
This means you don’t need to find the distribution of first — just integrate against the density of .
Intuition
Think of a production service emitting a metric (e.g., request latency in ms):
- Expectation is the long-run average — the number you’d see on a p50 or mean dashboard panel after many requests.
- Variance is the jitter — how far individual readings deviate from that average. High variance means unpredictable, bursty behaviour.
- Standard deviation is variance in interpretable units: “on average, latency deviates from the mean by ms.”
Linearity of expectation is like the additive property of latency in a call chain: , regardless of whether the two services are correlated.
ML Applications
- Loss functions — almost every loss function is an expectation: . Minimising training loss approximates minimising the true expected loss.
- Bias–variance tradeoff — the mean squared error of an estimator decomposes as . Regularisation trades higher bias for lower variance to reduce overall error.
- Stochastic gradient descent — computes a noisy, unbiased estimate of the true gradient . The variance of this estimate determines how large the learning rate can be.
- Moments in distributions — the mean and variance are the first two moments. They fully characterise a Gaussian distribution, and approximating a complex distribution by matching its moments is a common technique.