A percentile tells you the threshold below which a given percentage of observations fall. For example, if a server's 95th percentile (p95) response time is 180 ms, then 95% of requests finished in 180 ms or less while the slowest 5% took longer.
Percentiles give ML engineers and backend teams an honest view of tail behavior that averages completely hide.
Python 3.8+ includes statistics.quantiles() for splitting data into quartiles (n=4) or percentiles (n=100). In NumPy, np.percentile(data, [25, 50, 75, 95]) computes multiple thresholds at once.
import statistics
latencies_ms = [42, 48, 51, 55, 60, 63, 70, 82, 110, 295]
q1, median, q3 = statistics.quantiles(latencies_ms, n=4)
iqr = q3 - q1
upper_fence = q3 + 1.5 * iqr
print(f"Q1={q1}, Median={median}, Q3={q3}")
print(f"IQR={iqr}, Upper outlier threshold={upper_fence}")
Unlike mean and standard deviation, the Interquartile Range (IQR = Q3 - Q1) resists distortion from extreme spikes. Any point above Q3 + 1.5 * IQR or below Q1 - 1.5 * IQR is a classic box-plot outlier candidate.
$5,000 purchases or 295 ms spikes may be real fraud or timeout events your model needs to learn.60 ms can hide a p99 spike of 3 seconds affecting real users.Percentiles divide data into 100 equal parts (0–100), whereas quantiles generalize that idea to any count, such as quartiles (4 parts) or deciles (10 parts).
Call np.percentile(latencies, 99) (or np.quantile(latencies, 0.99)).
A box plot draws Q1, the median (Q2), and Q3 as the box, with whiskers extending to the 1.5 * IQR fences and dots marking outliers beyond them.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.