Math & Statistics

Expectation & Variance

The fundamental operators for measuring central tendency and dispersion in probability and machine learning.

🟢 beginner4 min readprobability
Expectation E[X] is the probability-weighted average of all possible values of random variable X. Variance Var(X) = E[(X - E[X])²] measures expected squared deviation from the mean, with properties Var(aX + b) = a²Var(X). In machine learning, E[X] and Var(X) form the foundation of loss functions, MSE bias-variance decomposition, batch normalization, and weight initialization.

Expectation: The Probability-Weighted Mean

For discrete random variable X with probability mass function P(X = x_i):

E[X] = ∑ x_i P(X = x_i)

For continuous random variable X with probability density function f(x):

E[X] = ∫ x f(x) dx

Key Properties of Expectation

Variance & Standard Deviation

Variance measures how spread out values are around the mean:

Var(X) = E[ (X - E[X])² ] = E[X²] - (E[X])²

Standard Deviation is SD(X) = √Var(X) (in original measurement units).

Key Properties of Variance

Applications in ML

  1. Batch Normalization: Subtracts sample expectation μ_B = E[X] and divides by sample standard deviation σ_B = √Var(X) to stabilize training.
  2. Weight Initialization: Xavier and He initializations set initial weight variance Var(W) = 2 / d_in to preserve activation variance across layers.
  3. Bias-Variance Decomposition: Test MSE decomposes into Bias[f̂]² + Var[f̂] + σ².

Say this out loud

"Expectation is the probability-weighted average E[X], while Variance Var(X) = E[X²] - (E[X])² measures expected squared spread around the mean. Linearity of expectation E[aX + bY] = aE[X] + bE[Y] holds always, but variance scaling squares constants: Var(aX + b) = a²Var(X). In ML, keeping expectation zero and controlling variance across layers is what prevents vanishing and exploding gradients."

Follow-ups to expect

Check yourself

Question 1 of 3

If random variable X has variance Var(X) = 4, what is the variance of Y = 3X + 5?

More in Math & Statistics

See all →
Bayes’ Theorem4 minCentral Limit Theorem4 minLaw of Large Numbers4 min