Isolation Forest Algorithm
What you'll learn: How Isolation Forest detects anomalies by isolating them with fewer random splits than normal points.
The Core Intuition
Imagine you're at a crowded party trying to find someone who stands alone in the corner. You could randomly divide the room with imaginary lines. The person in the corner would be separated from the crowd in just one or two splits, while reaching someone in the dense crowd would take many more divisions.
Isolation Forest works exactly this way. It builds random decision trees that split the data randomly. Anomalies are easier to isolate—they require fewer random splits to be separated from other points because they're far from dense regions. Normal points, clustered together, need many more splits to be isolated.
How Path Length Becomes an Anomaly Score
Each data point travels down a tree until it's isolated in its own leaf node. The path length (number of splits needed) becomes the anomaly score:
- Short path = Few splits needed = Point is isolated easily = Likely anomaly
- Long path = Many splits needed = Point is buried in density = Normal point
The algorithm builds multiple random trees (a forest) and averages the path lengths across all trees. Points with consistently short paths across the forest are flagged as anomalies.
Why This Works
Anomalies have two key properties:
- They are few in number
- They are different from normal points
Both properties make them susceptible to isolation—random splits will quickly separate them from the majority of data.
Key Takeaway: Isolation Forest detects anomalies by measuring how quickly random splits can isolate a point; shorter average path lengths indicate higher anomaly scores.