1.3.8Probability & Statistics

Expectation, variance, and standard deviation

2,070 words9 min readdifficulty · medium6 backlinks

Overview

These three concepts answer different questions about a random variable:

  • Expectation (Mean): Where is the "center" of the distribution?
  • Variance: How spread out are the values?
  • Standard Deviation: How spread out, in the same units as the original data?

They form the foundation for understanding data distributions, comparing models, and quantifying uncertainty in ML.


Expectation (Expected Value)

Derivation from First Principles

Why this definition?

Imagine you run an experiment NN times. Value xix_i appears nin_i times. The sample average is: Average=1Ninixi=ixiniN\text{Average} = \frac{1}{N} \sum_{i} n_i \cdot x_i = \sum_{i} x_i \cdot \frac{n_i}{N}

As NN \to \infty, the relative frequency niNP(X=xi)\frac{n_i}{N} \to P(X = x_i) (law of large numbers). So: limNAverage=ixiP(X=xi)=E[X]\lim_{N \to \infty} \text{Average} = \sum_{i} x_i \cdot P(X = x_i) = E[X]

For continuous variables: We divide the real line into tiny bins of width dxdx. The probability of landing in bin around xx is f(x)dxf(x) \, dx. Summing over all bins gives the integral definition.

Figure — Expectation, variance, and standard deviation

Why linearity? Expand the sum: E[aX+bY]=ij(axi+byj)P(X=xi,Y=yj)E[aX + bY] = \sum_i \sum_j (ax_i + by_j) P(X = x_i, Y = y_j) =aixiP(X=xi)+bjyjP(Y=yj)=aE[X]+bE[Y]= a \sum_i x_i P(X = x_i) + b \sum_j y_j P(Y = y_j) = aE[X] + bE[Y]


Variance

Derivation: Two Forms

Form 1 (definition): Average squared deviation from mean. Var(X)=E[(Xμ)2]\text{Var}(X) = E[(X - \mu)^2]

Form 2 (computational): Expand the square. Var(X)=E[X22μX+μ2]\text{Var}(X) = E[X^2 - 2\mu X + \mu^2] =E[X2]2μE[X]+μ2= E[X^2] - 2\mu E[X] + \mu^2

Why this step? Use linearity of expectation. E[X]=μE[X] = \mu and μ2\mu^2 is constant.

=E[X2]2μ2+μ2=E[X2]μ2= E[X^2] - 2\mu^2 + \mu^2 = E[X^2] - \mu^2

Why Form 2? Easier to compute—calculate E[X]E[X] and E[X2]E[X^2] separately, then subtract.

Why a2a^2 for scaling? Var(aX)=E[(aX)2](E[aX])2=a2E[X2]a2(E[X])2=a2Var(X)\text{Var}(aX) = E[(aX)^2] - (E[aX])^2 = a^2 E[X^2] - a^2 (E[X])^2 = a^2 \text{Var}(X)

Why shift invariant? Adding a constant moves the distribution but doesn't change spread. Var(X+b)=E[(X+bE[X+b])2]=E[(XE[X])2]=Var(X)\text{Var}(X + b) = E[(X + b - E[X+b])^2] = E[(X - E[X])^2] = \text{Var}(X)


Standard Deviation

Why take the square root? To return to the original scale. If you measure heights in cm, variance is in cm², but SD is in cm.


Common Mistakes


Why This Matters in ML

  1. Model Evaluation: Variance measures prediction uncertainty. High variance = model is inconsistent.
  2. Bias-Variance Tradeoff: Balancing systematic error (bias) vs. prediction spread (variance).
  3. Gradient Descent: Variance of gradient estimates affects learning stability (see: SGD, mini-batch size).
  4. Feature Scaling: Standardization uses mean and SD to normalize features: z=xμσz = \frac{x - \mu}{\sigma}.
  5. Probabilistic Models: Gaussian distributions are parameterized by μ\mu and σ2\sigma^2.
  6. Loss Functions: MSE (Mean Squared Error) is essentially variance of prediction errors.

Recall Explain to a 12-Year-Old

Imagine you and your friends are throwing darts at a board.

Expectation is where you aim—the bullseye. If everyone throws 100 times, the expectation is the average spot where all the darts landed.

Variance is how mesy your throws are. If all darts cluster tightly near the bullseye, variance is small. If they're scattered all over, variance is big. We measure it by looking at how far each dart is from the average spot, squaring those distances (so left and right don't cancel), and averaging them.

Standard deviation is the same as variance, but we take the square root at the end so it's in the same units—like "on average, darts land 5 cm away from the bullseye" instead of "25 cm²."

In AI, we use these to know if a model is consistent (low variance) or all over the place (high variance).


Connections


#flashcards/ai-ml

What is the expectation of a discrete random variable? :: E[X]=ixiP(X=xi)E[X] = \sum_i x_i \cdot P(X = x_i), the probability-weighted average of all possible values.

What does variance measure?
The average squared distance of values from the mean; quantifies spread or dispersion.
What is the computational formula for variance?
Var(X)=E[X2](E[X])2\text{Var}(X) = E[X^2] - (E[X])^2
How does variance scale with a constant multiplier?
Var(aX)=a2Var(X)\text{Var}(aX) = a^2 \text{Var}(X) (scaling by aa scales variance by a2a^2).
What is standard deviation?
The square root of variance, σ=Var(X)\sigma = \sqrt{\text{Var}(X)}, giving spread in original units.
For independent RVs, how do variances combine?
Var(X+Y)=Var(X)+Var(Y)\text{Var}(X + Y) = \text{Var}(X) + \text{Var}(Y) (variances add).
Why do we square deviations in variance?
To prevent positive and negative deviations from canceling, and to give algebraic properties like E[X2]μ2E[X^2] - \mu^2.
Does expectation obey linearity?
Yes, E[aX+bY]=aE[X]+bE[Y]E[aX + bY] = aE[X] + bE[Y] for any constants a,ba, b.
What is the variance of a constant?
Zero, Var(c)=0\text{Var}(c) = 0, because a constant has no spread.
If E[X]=5E[X] = 5 and E[X2]=30E[X^2] = 30, what is Var(X)\text{Var}(X)?
Var(X)=3052=3025=5\text{Var}(X) = 30 - 5^2 = 30 - 25 = 5.

Concept Map

centered by

spread measured by

derived from

computed via

computed via

obeys

defined as

deviation from

square root gives

expressed in

Random variable X

Expectation E X

Variance

Standard deviation

Law of large numbers

Linearity property

Discrete sum formula

Continuous integral formula

Average squared distance

Same units as data

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, expectation matlab long-run average hai. Agar tum ek dice 1000 baar roll karo, toh average value 3.5 ayega—yeh expectation hai. Formula simple hai: har possible value ko uski probability se multiply karo aur sab add kar do. Continuous distributions ke liye integral use hota hai, but logic same hai.

Variance bata hai ki data kitna spread out hai mean se. Agar sab values mean ke paas hain, variance chhota. Agar values scattered hain, variance bada. Formula: har deviation ko square karo (taki positive-negative cancel na ho), phir average nikalo. Computation ke liye shortcut: E[X2](E[X])2E[X^2] - (E[X])^2 use karo.

Standard deviation variance ka square root hai—yeh original units mein spread bata hai. Agar height cm mein hai, variance cm² mein hoga but SD phir se cm mein. ML mein yeh feature scaling (standardization), model consistency (low variance = stable predictions), aur bias-variance tradeoff mein kaam ata hai. Samjho: expectation = center, variance = spread, SD = spread in original units. Teen concepts, ek chain: μσ2σ\mu \to \sigma^2 \to \sigma.

Go deeper — visual, from zero

Test yourself — Probability & Statistics

Connections