Z-Scores
How unusual is it?.
Ana scored eighty five in maths and ninety in history. Which result is more impressive? You can't tell from the scores alone. It depends on how everyone else did. A z score answers that.

- 85 in maths, 90 in history
- Which is more impressive?
- It depends on everyone else
Distance in standard deviations
A z score is the value minus the mean, divided by the standard deviation. It says how many standard deviations a value is above, or below, average. Run it. Ana's maths score is one and a half standard deviations above the mean. History is only one and a quarter. So maths is the more impressive result.
def z(value, mean, std):
return (value - mean) / std
print("maths: ", z(85, mean=70, std=10))
print("history:", z(90, mean=85, std=4))maths: 1.5 history: 1.25
Reading z scores
A z score of zero is exactly average. Plus one is one standard deviation above. Minus two is two below. For bell shaped data, about ninety five percent of values have z scores between minus two and plus two. So a z score beyond three is very unusual, and often flagged as an outlier.
| key | value |
|---|---|
| z = 0 | exactly average |
| z = +1 | 1 std above |
| |z| < 2 | about 95% of data |
| |z| > 3 | very unusual |
Summary
A z score is a value's distance from the mean, in standard deviations. It lets you compare things on different scales. Next, using z scores to prepare features for machine learning.
Key takeaways- z = (x − mean) / std
- Compare across scales
- |z| > 3 is unusual