AI Hints
Statistics & Math for ML · Lesson 21 of 138

Z-Scores

How unusual is it?.

⏱ 2 min read▶ Video at 22:57🎓 Free
Watch this lesson in the Statistics & Math for ML courseWatch on YouTube ↗Full Statistics & Math for ML course

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.

Z-Scores
From the video: Z-Scores
  • 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.

zscore.pypython
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))
Output
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.

keyvalue
z = 0exactly average
z = +11 std above
|z| < 2about 95% of data
|z| > 3very 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
Next up: Standardizing Features — mean 0, std 1