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

Quartiles and Box Plots

The middle half.

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

The twenty fifth, fiftieth, and seventy fifth percentiles have a special name. The quartiles. They split the data into four equal parts. And a box plot draws them as a picture.

Quartiles and Box Plots
From the video: Quartiles and Box Plots
  • 25th, 50th, 75th percentiles
  • Four equal parts
  • A box plot draws them

The parts of a box plot

The box goes from the first quartile, Q one, to the third quartile, Q three. So it holds the middle half of the data. The line inside is the median. The whiskers reach out to the rest of the data. And dots beyond the whiskers are possible outliers.

BoxQ1 to Q3, the middle half
Linethe median
Whiskersthe rest of the data
Dotspossible outliers

Comparing groups

Box plots are great for comparing groups side by side. Here are delivery times from three shops. Run it. Shop B is fastest. Shop C has the widest box, so it's the least predictable, and it has some very slow outliers.

box.pypython
import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(3)
a = rng.normal(30, 4, 200)
b = rng.normal(22, 3, 200)
c = np.append(rng.normal(28, 9, 195), [70, 75, 80, 85, 90])

plt.boxplot([a, b, c], tick_labels=["Shop A", "Shop B", "Shop C"])
plt.title("Delivery time (minutes)")
plt.savefig("box.png")

Summary

Quartiles split data into four parts, and a box plot shows the middle half, the median, and the outliers. Next, finding outliers with a rule.

Key takeaways
  • Q1, median, Q3
  • Box is the middle half
  • Great for comparing groups
Next up: Finding Outliers — the IQR rule