Classical ML

Outlier & Anomaly Detection

Detecting anomalous data points that distort statistical metrics or represent fraud, intrusions, and system failures.

🟡 intermediate5 min readdata
Outlier and Anomaly Detection identifies observations that deviate significantly from expected normal data distributions. Statistical methods use Z-score thresholds or Interquartile Range (IQR bounds: Q1 - 1.5·IQR, Q3 + 1.5·IQR). Unsupervised ML algorithms include Isolation Forest (isolating anomalies via random splits), One-Class SVM (fitting tight decision boundaries around normal points), Local Outlier Factor (LOF), and Autoencoder reconstruction error thresholds.

Outlier Detection vs Novelty Detection

       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

AlgorithmMethod ClassKey ParameterBest Used For
IQR RuleUnivariate Statistical$Q1 - 1.5 \cdot \text{IQR}, Q3 + 1.5 \cdot \text{IQR}$Tabular numeric features
Z-score / Modified Z-scoreGaussian Statistical$Z
Isolation Forest (iForest)Tree-based Partitioningcontamination (expected % outliers)High-dimensional tabular data
One-Class SVMKernel Boundarynu ($\nu \in (0, 1]$ bounds outlier fraction)Complex non-linear boundaries
Local Outlier Factor (LOF)Local Densityn_neighbors (Compares local density)Variable-density spatial clusters
Autoencoder MSENeural ReconstructionReconstruction loss thresholdImages, 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 $s(x, n)$ for sample $x$ over $N$ trees:

$$s(x, n) = 2^{-\frac{\mathbb{E}[h(x)]}{c(n)}}$$

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

Check yourself

Question 1 of 3

Why is Isolation Forest faster and more effective for high-dimensional anomaly detection than distance-based outlier methods?

More in Classical ML

See all →
Bias–Variance Tradeoff4 minOverfitting vs Underfitting3 minLinear Regression4 min