Outlier & Anomaly Detection
Detecting anomalous data points that distort statistical metrics or represent fraud, intrusions, and system failures.
Outlier Detection vs Novelty Detection
- Outlier Detection (Unsupervised): Training data contains clean inliers AND undetected noise outliers. Algorithm must identify anomalies within the training set itself.
- Novelty Detection (Semi-Supervised): Training set contains strictly clean normal data. Algorithm learns normal baseline boundaries to flag unseen new anomalous events during inference.
STATISTICAL (IQR) ISOLATION FOREST AUTOENCODER
Outlier if x < Q1 - 1.5·IQR Short Path Length h(x) -> Anomaly High Reconstruction Error
or x > Q3 + 1.5·IQR Long Path Length h(x) -> Normal ||x - x̂||² > Threshold
Detection Toolkit Comparison
| Algorithm | Method Class | Key Parameter | Best Used For |
|---|---|---|---|
| IQR Rule | Univariate Statistical | Tabular numeric features | |
| Z-score / Modified Z-score | Gaussian Statistical | $ | Z |
| Isolation Forest (iForest) | Tree-based Partitioning | contamination (expected % outliers) | High-dimensional tabular data |
| One-Class SVM | Kernel Boundary | nu ( bounds outlier fraction) | Complex non-linear boundaries |
| Local Outlier Factor (LOF) | Local Density | n_neighbors (Compares local density) | Variable-density spatial clusters |
| Autoencoder MSE | Neural Reconstruction | Reconstruction loss threshold | Images, Audio, Time-Series |
Isolation Forest Mechanics
Isolation Forest builds an ensemble of random decision trees (iTrees) by randomly selecting a feature and a random split value:
Normal Point (Inlier) Anomalous Point (Outlier)
Deep Tree Path Length h(x) = 14 Short Tree Path Length h(x) = 2
(Takes many splits to isolate) (Isolated immediately near root!)
Anomaly score for sample over trees:
- : Average path length of across all trees.
- : Average path length of unsuccessful search in a Binary Search Tree.
- Score : Definite anomaly.
- Score : Normal inlier.
Say this out loud
"Outlier detection identifies anomalous data points. For univariate data, we use robust IQR bounds (Q1 - 1.5·IQR to Q3 + 1.5·IQR). For high-dimensional tabular data, Isolation Forest is the industry standard—it isolates anomalies via random decision tree splits, identifying outliers by short average path lengths h(x). For complex vision or time-series data, Autoencoders flag anomalies via reconstruction MSE spikes."
Follow-ups to expect
- Why is standard Z-score problematic for outlier detection? Z-score uses mean and standard deviation . Extreme outliers inflate and heavily, masking true outliers. Use Modified Z-score with Median and Median Absolute Deviation (MAD).
- What is MAD (Median Absolute Deviation)? . A robust non-parametric measure of statistical dispersion unaffected by extreme outliers.
Check yourself
Why is Isolation Forest faster and more effective for high-dimensional anomaly detection than distance-based outlier methods?