Explore Library
Code QuizIntermediate

Detecting Outliers with IQR

Find the flipped-sign bug that makes the IQR rule flag every value as an outlier.

Codepython
import numpy as np

data = np.array([11, 12, 12, 13, 12, 200])
q1 = np.percentile(data, 25)
q3 = np.percentile(data, 75)
iqr = q3 - q1

lower = q1 + 1.5 * iqr
upper = q3 - 1.5 * iqr

outliers = data[(data < lower) | (data > upper)]
print(outliers)

What is the bug in this IQR outlier-detection code?