Percentiles
Where do you rank?.
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.

- 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.
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}")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.
| key | value |
|---|---|
| 50th | the median |
| 25th, 75th | the quartiles |
| p99 | the slowest 1% |
| Use | thresholds, 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