← Back to the blog
Data analysis2026-06-20· 1 min

Outlier detection with the interquartile range (IQR)

JC

Javier Causil

Data scientist

Before modeling, it's worth checking how "unusual" a variable's extreme values really are. A simple and robust method (it doesn't assume normality) is the interquartile range.

The method

With Q1Q_1 and Q3Q_3 as the first and third quartiles, the interquartile range is:

IQR=Q3−Q1IQR = Q_3 - Q_1

A value xx is considered an outlier if it falls outside:

[ Q1−1.5⋅IQR,  Q3+1.5⋅IQR ][\,Q_1 - 1.5 \cdot IQR,\ \ Q_3 + 1.5 \cdot IQR\,]

Implementation

python
def find_outliers_iqr(series):
    q1, q3 = series.quantile(0.25), series.quantile(0.75)
    iqr = q3 - q1
    lower, upper = q1 - 1.5 * iqr, q3 + 1.5 * iqr
    return series[(series < lower) | (series > upper)]

When not to use it

The 1.5 is a convention, not a law of physics. With highly skewed distributions (income, waiting times) it's better to check visually with a boxplot before discarding data automatically — a genuine outlier may be the most important finding of the analysis.

Did you enjoy the article?