What Is Variance?
Press Next → or use ← → arrow keys
The Intuition — Two Delivery Apps
The average can't tell them apart — but variance can. Variance measures how much each value strays from the mean, capturing exactly the consistency that the average hides.
Low variance means values cluster tightly around the mean (App A). High variance means they scatter far and wide (App B). It's the first and most important measure of how consistent a dataset is.
The Average Hides This Difference
Both rows centre on the same purple mean line, yet App B's variance is about 500× larger than App A's. That single number is what tells you App A is dependable and App B is a gamble — the whole reason variance exists.
How It's Built — Deviations, Then Squares
1. Measure each point's deviation from the mean (blue below, amber above). 2. Square each deviation — the purple squares, whose areas are 4, 1, 0, 1, 4. 3. Average those squared areas. That average is the variance.
Why Square The Deviations?
You could average the absolute deviations (that's the "mean absolute deviation"), and it's also valid. But the absolute-value function has a sharp corner at zero that's awkward for calculus, while the squared version is smooth everywhere — which is exactly why variance became the standard the whole field is built on.
Population vs Sample Variance
The recipe is identical — deviations, squared, summed. What differs is the bottom of the fraction: divide by N when you have the whole population, and by n − 1 when you have a sample. Getting this one choice right is the most common variance decision in practice.
Why n − 1? Bessel's Correction
A handful of sampled points almost always looks tighter than the full population — they rarely
capture the true extremes. Dividing by n − 1 instead of n makes the fraction slightly
bigger, correcting that downward bias so s² is an honest estimate of σ².
Both Apps, Computed In Full
Both apps average exactly 30 minutes — but App A's variance is 1.33 and App B's is 667.33. That ~500× gap is the mathematical fingerprint of "dependable" vs "unpredictable," invisible to the mean alone.
From Squared Units To Something Readable
Because variance squares the deviations, its units are squared too — minutes², rupees², cm² — which nobody can picture. Taking the square root gives the standard deviation, back in the original units and instantly interpretable: "typically within ~1.15 minutes of 30."
Variance vs Standard Deviation
| Aspect | Variance (σ² / s²) | Standard Deviation (σ / s) |
|---|---|---|
| Definition | Average squared deviation | Square root of variance |
| Units | Squared (min², ₹²) | Original (min, ₹) |
| Human-readable? | No | Yes |
| Best for | Maths & ML operations | Reporting & interpretation |
| Example | 1.33 min² | 1.15 min |
They're the same measurement in different clothes. Use variance inside formulas — it adds cleanly, powers PCA and ANOVA, and behaves well under calculus. Use standard deviation when you talk to humans, because it lives in the units they understand.
Four Properties Worth Memorizing
A single mistaken data point — a delivery logged as 700 minutes instead of 70 — can dominate the entire variance because its deviation gets squared. Always screen for outliers before trusting a variance, and consider robust alternatives like the IQR when they're present.
Where Variance Runs The Show
In machine learning, a model's error splits into bias (too simple) and variance (too sensitive to the training data). Managing that variance — through regularization, more data, or ensembling — is one of the central skills of building models that generalize.
Computing Variance — Mind The ddof
import numpy as np import statistics data = [29, 31, 30, 28, 32, 30, 29, 31, 30, 30] # ── NumPy ── mind the divisor! np.var(data, ddof=1) # 1.33 — SAMPLE variance (÷ n−1) ← usually what you want np.var(data, ddof=0) # 1.20 — POPULATION variance (÷ n) ← NumPy's default! # ── statistics module (clearer names) ── statistics.variance(data) # sample (÷ n−1) statistics.pvariance(data) # population (÷ n)
np.var() defaults to ddof=0 — the population variance. In almost all
data-science work you're holding a sample, so you want ddof=1. Forgetting this silently
gives you the wrong (too-small) number, and it's one of the most common statistics bugs in real code.
Six Rules For Working With Variance
ddof=1 in NumPy. Its default of ddof=0 is the population formula.You Now Understand Variance
Variance is the average squared distance from the mean — the number that turns "average 30 minutes" into "dependable" or "a gamble." Square the deviations, average them (÷ n−1 for a sample), and take the root for a human-readable standard deviation. It's the foundation of risk, PCA, ANOVA, and the bias–variance tradeoff.
Pair variance with its readable twin standard deviation, then explore covariance and correlation (how two variables vary together), and see variance in action inside PCA and the bias–variance tradeoff.
📐 End of tutorial · Press ← to review, or click Restart