Notes

Interquartile Range (IQR)

The interquartile range is a simple way to describe how “spread out” your data is without letting a few extreme values hijack the story. It focuses on the middle of the data—the part that usually represents what’s typical.

What IQR means
The Interquartile Range (IQR) measures the width of the middle 50% of a dataset. You first find the first quartile (Q1) (the 25th percentile) and the third quartile (Q3) (the 75th percentile). Then:

IQR = Q3 − Q1

If Q1 is 40 and Q3 is 70, the IQR is 30. That “30” tells you how much the central half of values varies.

Why it’s robust (and when that helps)
Unlike the range (max − min) or even the standard deviation, the IQR is robust to outliers. A single bizarre value—like a house listed at $50 million in a dataset of $300k homes—barely changes Q1 and Q3, so the IQR stays stable and informative.

Practical examples

  • House prices: IQR summarizes typical price variability across neighborhoods without being distorted by luxury properties.
  • Exam scores: IQR shows how spread out the “middle students” are, even if a few students score 0 or 100.
  • Medical lab values: IQR helps describe typical patient variation when a handful of measurements are erroneous or extreme.

Why it matters in AI/ML
IQR is commonly used for outlier detection via the 1.5×IQR rule: values below Q1 − 1.5·IQR or above Q3 + 1.5·IQR are flagged. This can improve data cleaning, stabilize model training, and prevent models from overreacting to rare anomalies. You’ll see it in box plots and in libraries like pandas (quantile) and NumPy (percentile).

Interquartile Range (IQR) is a robust measure of spread defined as Q3 − Q1, the difference between the 75th and 25th percentiles. It summarizes the variability of the middle 50% of data and is less sensitive to outliers than the standard deviation. In AI/ML, IQR helps detect anomalies and guide preprocessing; for example, boxplot rules flag points below Q1 − 1.5·IQR or above Q3 + 1.5·IQR.

Imagine you’re looking at everyone’s commute times to work. A few people might have extreme trips (like a 2-hour commute), but you want a sense of the “typical spread” without those unusual cases dominating the picture. The Interquartile Range (IQR) does exactly that.

To find it, you sort the numbers and look at the middle half of the data: from the 25th percentile (where a quarter of values are below) to the 75th percentile (where three-quarters are below). The IQR is the difference between those two points, showing how spread out the central chunk of values is, while being less sensitive to outliers.