Outlier Detection Methods
Learn IQR, z-score, MAD, and isolation forest methods for detecting outliers in data
Outlier Detection Methods
Outliers are data points that differ significantly from the rest. Move the test point and switch the detection method below to see how each technique draws the line on the same data.
The Data
Every method below works on the same sample of 30 measurements: 29 fixed values, roughly bell-shaped around 50 with one mildly unusual value at 72, plus a test point you control.
Test point :
From these 30 values: mean =
Detection method:
The plot shows the data as dots along the bottom row and, above them, each method's normal range computed from those same 30 values. A value outside a band is flagged by that method; the markers on each row turn red for flagged and green for normal, for both and the value 72.
One Dataset, Three Outlier Fences
Right now the z-score rule flags
IQR (Interquartile Range) Method
The IQR method uses quartiles instead of and , making it robust to existing outliers.
(25th percentile):
(75th percentile):
Multiplier :
Point
Drag (
Comparing the Methods
On this sample the three fences agree while stays near the others, and disagree once it moves away: the z-score fence moves with every value, the IQR and MAD fences mostly ignore the extremes. Raising any threshold (, , or the MAD threshold) widens that method's band and flags fewer values. Switch methods (
Try it in Code
# Outlier detection: Z-score, IQR, and MAD methods
import numpy as np
mu, sigma = 51.06666666666667, 6.591181848570068
x = 60
q1, q3 = 47, 54
# Z-Score method
z = (x - mu) / sigma
print(f"Z-Score: {z:.3f} -> {'OUTLIER' if abs(z) > 3 else 'NORMAL'}")
# IQR method
iqr = q3 - q1
lower, upper = q1 - 1.5 * iqr, q3 + 1.5 * iqr
print(f"IQR Fences: [{lower:.2f}, {upper:.2f}] -> {'OUTLIER' if x < lower or x > upper else 'NORMAL'}")
# MAD method
med, mad_val = 50.5, 3.5
mod_z = 0.6745 * (x - med) / mad_val
print(f"Modified Z-Score: {mod_z:.3f} -> {'OUTLIER' if abs(mod_z) > 3.5 else 'NORMAL'}")What to explore next
Birthday Paradox
Explore the surprising probability that two people share a birthday
Comparing Distributions with Box Plots
Visualize and compare multiple datasets using box plots and five-number summaries
Correlation Explorer
Visualize and understand correlation strength and direction
Cross-Validation Techniques
Learn k-fold, stratified, and leave-one-out cross-validation for robust model evaluation
You might also like
Comparing Distributions with Box Plots
ExplorationVisualize and compare multiple datasets using box plots and five-number summaries
Percentiles and Quartiles
ExplorationUnderstand data position with percentiles, quartiles, and the interquartile range
Back-to-Back Stem-and-Leaf Plots
ExplorationCompare two distributions side-by-side using back-to-back stem-and-leaf plots
Birthday Paradox
ExplorationExplore the surprising probability that two people share a birthday