Foundations of Data Science slides 📂 Introduction · 5 of 10 36 min read

What Is Standard Deviation?

Variance in units you can read. Standard deviation answers "on average, how far is each value from the mean?" — the everyday ruler for spread. This tutorial covers its link to variance, population vs sample formulas, a worked example, the 68-95-99.7 empirical rule, z-scores, anomaly detection at ±3σ, quality-control and ML applications, and the NumPy ddof trap — with animated diagrams.

📏

What Is Standard Deviation?

Variance in units you can actually read. Standard deviation answers "on average, how far is each value from the mean?" — the everyday ruler for spread, and the backbone of the 68-95-99.7 rule.
Spread in Real Units 68-95-99.7 Z-Scores ±3σ Outliers

Press Next → or use ← → arrow keys

Section 01

The Intuition — Two Packing Machines

Both average 20 g — but only one is trustworthy
Two machines fill snack packets to a 20 g target. Sample five packets from each and both average 20 g. But Machine A's packets weigh 19.8–20.2 g every time, while Machine B swings from 14 g to 26 g. Same mean, completely different reliability.

Standard deviation captures exactly that: Machine A's is 0.15 g, Machine B's is 4.36 g. It answers the question the mean can't — "on average, how far does each value land from the middle?"
💡
Average Distance From The Mean

Standard deviation is the typical distance between a data point and the mean, expressed in the same units as the data. Small σ = consistent and predictable; large σ = scattered and unreliable.

Section 01 · Diagram

Consistency You Can Measure

target = 20 g (both average 20) Machine A · σ = 0.15 g tight → reliable ✓ Machine B · σ = 4.36 g 14 g … 26 g → unpredictable ✗
🏭
This Is Why Factories Track σ, Not Just The Mean

Machine B occasionally underfills to 14 g (angry customers) and overfills to 26 g (wasted product) — even though its average is a perfect 20. Standard deviation is the number quality control actually cares about, because it measures the consistency the mean hides.

Section 02 · Definition

Variance, Made Readable

Standard deviation
σ = √(variance)
The square root of variance — which pulls the units back down to the original scale.
The units win
0.023 g² → √ → 0.15 g
"0.023 grams-squared" is meaningless; "0.15 grams" is instantly understandable.
🔗
Same Information, Human Units

Variance and standard deviation carry the same information about spread — but variance lives in squared units nobody can picture. Taking the square root gives standard deviation, which sits in the data's own units, so you can say "packets vary by about 0.15 g on average."

Section 02 · Formulas

Population vs Sample

Population standard deviation
σ = √( Σ(xᵢ − μ)² / N )
Every squared deviation from μ, averaged over all N members, then rooted.
Sample standard deviation
s = √( Σ(xᵢ − x̄)² / (n − 1) )
Divide by (n − 1) — Bessel's correction — for an unbiased estimate from a sample.
The n − 1 Rule Carries Over From Variance

Because standard deviation is just the root of variance, the same divisor logic applies: use N for a full population and n − 1 for a sample. A sample tends to look tighter than the true population, and (n − 1) nudges the estimate up to correct that bias.

Section 03 · Worked Example

Eight Exam Scores, Step By Step

Scores: 52, 74, 68, 90, 61, 85, 72, 78. Work the sample standard deviation all the way through.

1 · Mean
580 / 8 = 72.5
Add the eight scores and divide by the count.
2 · Sum of squared deviations
420.25 + 2.25 + … = 1068
Square each score's distance from 72.5 and add them all up.
3 · Variance (÷ n−1)
1068 / 7 = 152.57
Average squared deviation — still in "marks squared."
4 · Standard deviation (√)
√152.57 = 12.35 marks
Back in marks — the readable answer.
🎓
What 12.35 Actually Tells You

The class averaged 72.5, and students typically scored within about ±12 marks of that — so most fell roughly between 60 and 85. One number now describes both where the class sits and how spread out it is.

Section 04 · The Empirical Rule

The 68-95-99.7 Rule

μ −1σ +1σ −2σ +2σ −3σ +3σ 68% 95% 99.7%
🔔
σ Turns Into A Probability Ruler

For normally distributed data, 68% of values land within ±1σ of the mean, 95% within ±2σ, and 99.7% within ±3σ. Standard deviation stops being an abstract number and becomes a map of where the data actually lives.

Section 04 · In Practice

Heights: Mean 175 cm, σ = 7 cm

68%168–182 cm (±1σ)
95%161–189 cm (±2σ)
99.7%154–196 cm (±3σ)
0.3%<154 or >196 cm
📊
Instantly Judge How Rare A Value Is

With mean 175 cm and σ = 7 cm, a man of 189 cm sits at exactly +2σ — taller than about 97.5% of men. Someone over 196 cm is beyond +3σ, in the rarest 0.15%. The empirical rule lets you turn any measurement into a "how unusual is this?" in your head.

⚠️
Only For Roughly-Normal Data

The 68-95-99.7 rule assumes a bell shape. On heavily skewed data (incomes, wait times) it breaks down — so always visualize the distribution first before trusting those percentages.

Section 05 · Z-Scores

Standardizing With Z-Scores

Raw heights (cm) · mean 175, σ ≈ 13.5 175 160 175 180 155 190 z = (x − μ) / σ ↓ Standardized (z) · mean 0, σ 1 0 −0.91 0.15 0.54 −1.30 1.52
🎯
"How Many σ From The Mean?"

A z-score rewrites every value as its distance from the mean in units of σ. It recenters the data to mean 0 and σ 1, so you can compare apples to oranges — a height and an exam score — and spot how extreme any single point is. It's exactly what StandardScaler does for ML.

Section 06 · Outliers

Flagging Anomalies At ±3σ

mean 120ms +3σ (153ms) 500ms · ANOMALY ≫ +3σ → flag it 🚨
🚨
Beyond 3σ Is Almost Certainly Not Noise

If server response times average 120 ms with σ = 11 ms, anything past mean + 3σ (~153 ms) is in the rarest 0.15% — so a 500 ms spike is a genuine anomaly, not random variation. The "mean ± 3σ" rule powers fraud alerts, fault detection, and lab flags across the board.

Section 07 · Comparison

Standard Deviation vs Variance

PropertyVariance (σ² / s²)Standard Deviation (σ / s)
DefinitionAverage squared deviationSquare root of variance
UnitsSquared (g², ms²)Same as data (g, ms)
InterpretabilityHardEasy
Where it's usedPCA, ANOVA, proofsReporting, scaling, outliers
Empirical ruleNot directly68-95-99.7 in σ units
🤝
Two Tools, One Measurement

Keep variance for the maths — it adds cleanly and powers PCA and ANOVA. Reach for standard deviation whenever a human needs to understand the spread, because it speaks in the data's own units and plugs straight into the empirical rule.

Section 08 · Applications

Where Standard Deviation Works

🏭
Quality Control
Six Sigma keeps defects within ±6σ of target. σ is the yardstick for a stable, capable process.
💹
Finance
The standard deviation of returns is volatility — the headline risk number for any asset or portfolio.
🤖
ML Feature Scaling
StandardScaler divides by σ so SVMs, KNN, and neural nets aren't dominated by large-scale features.
🎯
The Common Thread

Whether it's a defect limit, an investment's risk, or a rescaled feature, they all rest on the same idea: measure spread in real units and count it in σ. Master standard deviation and three different fields open up at once.

Section 09 · Code

Computing σ — Mind The ddof

import numpy as np
import statistics

scores = [52, 74, 68, 90, 61, 85, 72, 78]

# ── NumPy — set the divisor! ──
np.std(scores, ddof=1)   # 12.35 — SAMPLE (÷ n−1)  ← usually correct
np.std(scores, ddof=0)   # 11.57 — POPULATION (÷ n) ← NumPy default!

# ── statistics module (clearer names) ──
statistics.stdev(scores)    # 12.35 sample
statistics.pstdev(scores)   # 11.57 population
🛑
The Same NumPy Trap As Variance

np.std() defaults to ddof=0 — the population divisor — which underestimates the spread of a sample. For nearly all data-science work you want ddof=1. It's a silent, one-character bug that quietly shrinks every standard deviation you report.

Section 10 · Golden Rules

Six Rules For Standard Deviation

🏅 Standard Deviation, Distilled
1Report σ, not variance, to people. It lives in the data's own units and reads naturally.
2Use ddof=1 in NumPy for sample data — the default ddof=0 understates the spread.
3Apply 68-95-99.7 only to roughly-normal data. Visualize the shape before trusting it.
4Use z-scores to compare across scales and to flag values that sit many σ from the mean.
5Flag points beyond mean ± 3σ as anomalies — but confirm they aren't just heavy tails.
6A zero σ is a red flag. Every value is identical — the feature carries no information.
Wrap-Up

You Now Understand Standard Deviation

√varSame units as data
÷(n−1)Sample formula
68-95-99.7Empirical rule
z(x−μ)/σ
±3σOutlier flag
ddof=1NumPy sample
🎯
The Through-Line

Standard deviation is the square root of variance — the average distance from the mean, in the data's own units. It turns "spread" into a readable number, powers the 68-95-99.7 rule and z-scores, and draws the line between normal variation and genuine anomalies.

📚
Where To Go Next

Connect σ to the normal distribution in depth, then explore covariance and correlation (how two variables move together) and confidence intervals, where standard deviation becomes the engine of inference.

📏 End of tutorial · Press to review, or click Restart