Statistics — Making Sense of Data
What you'll learn
- Mean, median, mode — and when each lies
- Spread: why the average alone fools you
- Probability basics
- You'll compute real statistics in Python
The averages that lie 📊
Data science begins with statistics: the art of summarizing many numbers into a few that tell the truth (or a lie, if you're careless).
Three "middles":
- Mean (average) — add everything, divide by count.
[2,4,6]→ 4. - Median — the middle value when sorted.
[2,4,90]→ 4. Notice the mean is 32, but the median is 4! - Mode — the most frequent value.
Why it matters: imagine 9 workers earn $40k and the boss earns $1,000k. The mean salary is $136k — a number nobody actually earns. The median is $40k — the honest "typical" worker. Outliers (extreme values) wreck the mean but barely move the median. This is the #1 way statistics mislead people, so always ask which average.
Spread tells the rest of the story. Two classes both average 70% on a test. Class A: everyone scored 68–72. Class B: half scored 40, half scored 100. Same mean, totally different reality. Standard deviation measures this spread — small = clustered, large = scattered. The average without the spread is half a story.
Probability is just "how likely, from 0 to 1." A fair coin: P(heads) = 0.5. It underlies everything predictive — a spam filter really outputs "0.92 probability this is spam."
These aren't abstract: every chart you'll build and every model you'll train rests on knowing what your numbers actually say.
Correlation is not causation 🔗
Once you can summarize one variable (mean, median, spread), the next question is almost always: do two variables move together? That's correlation — a number from -1 to 1 describing how closely two variables track each other.
- +1 — perfect positive: as one goes up, the other always goes up too (e.g. height and shoe size).
- -1 — perfect negative: as one goes up, the other always goes down (e.g. price and quantity sold, roughly).
- 0 — no relationship at all.
In Python, df["ice_cream_sales"].corr(df["temperature"]) might return something like 0.85 — a strong positive correlation. Tempting conclusion: "heat makes people buy ice cream!" That one's probably true — but the general trap is real: correlation only tells you two things move together, never that one causes the other.
The classic teaching example: ice cream sales and drowning deaths are strongly correlated across the year. Does ice cream cause drowning? No — a hidden third variable (hot summer weather) drives both: more people swim and more people buy ice cream. This hidden driver is called a confounding variable, and hunting for it is one of the most important habits a data scientist builds. Every time you see "X correlates with Y" in a headline, ask: could something else be causing both?
This is why real experiments (like A/B tests, covered elsewhere) exist — they're the main tool that lets you go from "these move together" to "this actually causes that."
Compute the two most important statistics. Write mean(nums) and median(nums):
mean= sum ÷ countmedian= the middle value after sorting (for an even count, average the two middle values)
Example: median([3, 1, 2]) → 2; median([1, 2, 3, 4]) → 2.5
Write same_direction_count(xs, ys) — a tiny taste of correlation without any library. Given two equal-length lists, count how many consecutive pairs move in the "same direction": both increase, or both decrease, from one index to the next.
Example: xs=[1,2,3,4], ys=[5,6,5,8] → steps: xs always rises; ys rises, falls, rises → matches at steps 0 and 2 → 2. This is the intuition behind correlation: do two series tend to move together?
Real-world case study: Anscombe's Quartet 🔍
In 1973, statistician Francis Anscombe built four small datasets — now called Anscombe's Quartet — that each have nearly identical mean, variance, and correlation. If you only looked at the summary numbers, you'd think all four datasets were the same.
They aren't. When plotted, the four look completely different: one is a clean straight-line relationship, one is a clear curve that a straight-line summary misrepresents, one is a perfect line wrecked by a single outlier, and one is a vertical cluster driven entirely by one extreme point. Same statistics, four totally different stories.
Anscombe built this specifically to warn statisticians against trusting summary numbers alone. It's the direct ancestor of the advice in this lesson and the next one on visualization: always plot your data. A mean, a median, and a correlation coefficient are useful shorthand — but they can hide a shape your eyes would catch in half a second.
Question 1 of 5
9 people earn $40k, 1 earns $1M. Which is the honest 'typical' value?
Question 2 of 5
Two classes average 70%. Why might they be very different?
Question 3 of 5
A probability of 0.92 means…
Question 4 of 5
Ice cream sales and drowning deaths correlate strongly. Why?
Question 5 of 5
What did Anscombe's Quartet prove?
Summary
- Mean vs median vs mode — outliers wreck the mean, median stays honest
- Spread (standard deviation) is as important as the average
- Probability (0–1) underlies all prediction
- Correlation (-1 to 1) shows two variables move together — but never proves one causes the other; watch for confounding variables
- You coded mean, median, and a same-direction correlation check from scratch
- Anscombe's Quartet shows why you must plot data, not just summarize it
Next: Python for Data — pandas, the tool that makes real-world data analysis fast.
Practice
Reading is not learning until you run something. Pick one.