AI Hints
Home›Statistics & Math for ML Tutorial›Percentiles and Outliers
Statistics & Math for ML · Lesson 16 of 138

Percentiles

Where do you rank?.

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

If you're told you scored in the ninetieth percentile, it means you did better than ninety percent of people. Percentiles describe where a value ranks, and they're robust to outliers, just like the median.

Percentiles
From the video: Percentiles
  • 90th percentile
  • Better than 90%
  • Robust, like the median

np.percentile

We simulate ten thousand exam scores. NP dot percentile takes the data, and which percentiles we want. The fiftieth percentile is the median. Run it. Ninety percent of students scored below about eighty.

percentiles.pypython
import numpy as np

rng = np.random.default_rng(1)
scores = rng.normal(65, 12, 10_000)

for p in [10, 25, 50, 75, 90]:
    print(f"{p}th percentile: {np.percentile(scores, p):.1f}")
Output
10th percentile: 49.6
25th percentile: 56.8
50th percentile: 64.9
75th percentile: 73.0
90th percentile: 80.0

Where percentiles show up

Children's growth charts use percentiles. So do salary reports, and website speed. A website's ninety ninth percentile load time tells you how slow it is for the unluckiest one percent of visitors, which the average would hide. In machine learning, percentiles help find thresholds and outliers.

keyvalue
50ththe median
25th, 75ththe quartiles
p99the slowest 1%
Usethresholds, outliers

Summary

A percentile tells you the value that a given percentage of the data falls below. The fiftieth is the median. Next, quartiles and box plots.

Key takeaways
  • np.percentile(x, p)
  • 50th = median
  • Robust to outliers
Next up: Quartiles and Box Plots — the middle half