The interquartile range (IQR) measures the spread of the middle half of a numeric distribution: IQR = Q3 − Q1, where Q1 and Q3 are the 25th and 75th percentiles. Because it uses quartiles and the median rather than the mean and standard deviation, it is more robust to outliers than a z-score. section 2.1.2
Use the IQR method to identify unusually extreme values in a numeric sequence:
- Calculate Q1 and Q3, then subtract Q1 from Q3 to obtain the IQR. section 2.1.2
- Set lower and upper outlier limits to Q1 − 2.2 × IQR and Q3 + 2.2 × IQR. Other coefficients are possible; Tukey’s traditional coefficient is 1.5. section 2.1.2
- Treat values outside the limits as candidates for investigation, not automatically meaningful anomalies. section 2.0
IQR-based anomaly detection
For a pandas Series, calculate the 25th and 75th percentiles, derive their difference, and compute lower and upper limits. In a time series, ADTK provides InterQuartileRangeAD; its coefficient can be increased, such as 20.0, when many extreme values would otherwise be flagged. section 2.1.2 section 17.3.1
import pandas as pd import numpy as np data = pd.Series(np.random.normal(size=10_000)) q1 = data.quantile(0.25) q3 = data.quantile(0.75) iqr = q3 - q1 iqr_lower_limit = q1 - (2.2 * iqr) iqr_upper_limit = q3 + (2.2 * iqr)
Inspect the concise pandas and NumPy implementation of quartile calculation and IQR thresholds. section 2.1.2
IQR is primarily a univariate method applied to individual numeric columns. It can quickly expose dominant extreme values before more detailed detection, but it does not capture relationships across a full table. Boxplots use an IQR-based whisker rule, commonly with a 1.5 coefficient, although multimodal data can make quartile-based judgments misleading. section 2.0 section 2.3.2






