Isolation Forest infographic
PHASE 7 ยท ANOMALY DETECTION ยท ALGORITHM 28/30

Isolation Forest

Finding outliers by how quickly they can be isolated

๐Ÿ’กCore Concept

Anomalies are few and different. Isolation Forest builds an ensemble of random binary trees that split data on random features at random thresholds. Because outliers sit apart from the crowd, a few random cuts isolate them โ€” so they land at shallow leaves with short path lengths. Normal points, buried in dense regions, need many splits to isolate. Short average path = anomaly.

๐ŸงฉKey Components

Random SplittingPick a random feature & a random split value between its min and max โ€” no distance metric needed.
Path Length h(x)Number of edges from root to the leaf that isolates a point. The core anomaly signal.
Ensemble of iTreesMany trees on random subsamples; average path length across trees stabilizes the score.
Distribution-FreeNo assumption of Gaussian/clusters. Works on high-dim, mixed data out of the box.

โš™๏ธHow It Works

  1. Draw a random subsample; build an isolation tree by recursively picking a random feature and random split until points are isolated or max depth is hit.
  2. Repeat to grow a forest of many independent iTrees.
  3. For each point, measure its path length in every tree and average it: E(h(x)).
  4. Convert to an anomaly score โ€” shorter average path โ‡’ score closer to 1.
s(x, n) = 2โˆ’E(h(x)) / c(n)
s โ†’ 1 : likely anomaly  ยท  s โ†’ 0.5 : normal  ยท  c(n) normalizes for sample size

๐ŸŒReal-World Applications

๐ŸŽฏCheckpoint

Why are anomalies easier to isolate than normal points?
How does path length translate into an anomaly score โ€” and why average it over many trees?
Contrast Isolation Forest with DBSCAN: when would you reach for each on the same outlier task?