Isolation Forest

Anomalies are easy to cut off from everything else. Count the cuts, and you have an anomaly score without ever modelling normal.

Isolation Forest

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

Split the data on a random feature at a random value, repeatedly, until each point is alone.
Points in sparse regions get cut off in a few splits. Points in dense regions need many.
The score is the average path length across many trees, normalised. Short path, high score.
It never learns what normal looks like — only what is easy to separate, which is why it needs no labels.

Overview

Many anomaly detectors model what normal data looks like and flag points that do not fit. Isolation Forest reverses the question: how quickly can random partitions isolate a point? Unusual points often have shorter paths than points in dense regions.

In this guide
  1. From path length to anomaly score
  2. Explore the forest
  3. Strengths and limitations
  4. Sources and next steps

From path length to anomaly score

Each tree repeatedly chooses a feature and a split value. The number of splits needed to isolate a point is its path length. Isolation Forest averages path lengths across trees and normalises for the sample size; shorter paths produce higher anomaly scores under the convention shown here.

An isolated point may be separated by one or two splits because many random cuts fall in the empty space around it. A point inside a dense group usually needs more cuts. This score ranks points; it is not a probability that a point is truly anomalous.

Explore the forest

  1. Set Trees to 5, then raise it toward 60. Change Forest seed to compare runs. With more trees, the flagged set should become less sensitive to a single random forest.
  2. Adjust Score threshold and inspect how many points are flagged. The cutoff changes the decision; it does not change the underlying observations or prove that a point is an anomaly.
  3. Change Points sampled per tree to see how the subsample affects paths and the result.

The visualiser uses a two-dimensional example. In an application, inspect flagged cases and validate the threshold with domain knowledge or labelled examples when available.

Strengths and limitations

Isolation Forest does not require labelled anomalies or a distance metric, and it can be efficient on large datasets. Its random axis-aligned splits can be less effective when anomalies are only locally unusual, when irrelevant features dominate the splits, or when the meaningful structure is strongly rotated or dependent across features.

The threshold is a separate decision from the ranking. Some implementations expose a contamination setting to choose a cutoff based on an assumed fraction of outliers; that assumption should reflect the use case, not be treated as a measured anomaly rate. Compare with Local Outlier Factor when local density differences matter, or DBSCAN when density-based clusters are the goal.

Sources and next steps

The method was introduced by Liu, Ting and Zhou in “Isolation Forest”. See scikit-learn’s outlier-detection guide for implementation details and score conventions.

Check yourself

0 of 3

Answer without scrolling back up.

  1. Why does a short average path length mean a point is anomalous?

  2. Why is each tree built from a small subsample?

  3. Which anomaly does Isolation Forest tend to miss?

Cheat sheet

Isolation Forest

Watch isolation forest flag anomalies by counting how few random splits isolate a point. Fewer splits means the data point is stranger.

MACHINE LEARNING · vizlearn.in/machine_learning/isolation_forest.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.