Isolation Forest

Machine Learning
Introduced by
Liu, F.T., Ting, K.M. & Zhou, Z.-H.
Year
2008
Type
Unsupervised ensemble (random partitioning trees)

What does it do?

Isolation Forest is an unsupervised machine-learning method for anomaly and outlier detection, introduced by Liu, Ting and Zhou in 2008, that isolates anomalies through random partitioning of the data.

It works without any labelled anomaly data and performs well on high-dimensional datasets that contain many irrelevant attributes.

The intuition behind the method

The core idea is simple: anomalies are few and different, so they are easy to separate from the rest of the data. If you keep splitting the data at random, a normal point sits in a dense region and takes many cuts to isolate, whereas an outlier sits apart and gets cut off after only a few splits. Counting how many splits it takes to isolate each point turns this intuition into an anomaly score.

History

Isolation Forest was introduced by Fei Tony Liu, Kai Ming Ting and Zhi-Hua Zhou in 2008 at the IEEE International Conference on Data Mining. Its central idea is to isolate anomalies directly rather than to profile normal data and measure deviation from it. The original empirical evaluation compared it with ORCA, LOF and random forests in terms of AUC and processing time, with emphasis on large data sets. Results on other data may differ from those reported, so performance should be checked on the data at hand.

When to use it

Choose Isolation Forest to flag anomalies in numeric data when no labelled anomalies are available for a supervised model, particularly when the dataset is large or has many features. The original evaluation reports good performance when many attributes are irrelevant and when the training set contains no anomalies. Be cautious when the sample is small: the original paper does not evaluate small samples, so the reliability of flags on such data is unverified. It is also a poor choice when you need an explanation of why a point is anomalous or calibrated probabilities, since it returns relative anomaly scores. Categorical variables must be encoded as numbers beforehand.

Limitations and considerations

  • The original paper does not evaluate small samples, so the reliability of flags on small datasets is unverified and such flags need extra scrutiny.
  • Scores are relative rankings; the method does not show which feature made a point anomalous.
  • Turning scores into flags requires a threshold that the score itself does not supply, so the cut-off has to come from domain knowledge.
  • Anomalies that form dense groups may need many splits to isolate and can therefore receive scores closer to those of normal points, because the method's logic assumes anomalies are few and different. This follows from the method's design rather than from a result reported in the original evaluation, so it should be checked on your own data.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Requires no labelled anomalies: it isolates outliers without modelling normal behaviour, and the original paper evaluates it on training sets that contain no anomalies.
  • Linear time complexity with a low constant and low memory requirement, made possible by sub-sampling, as reported in the original paper.
  • In the original empirical comparison, it performed favourably against ORCA, LOF and random forests in AUC and processing time, especially on large datasets.
  • The original evaluation reports that it remains effective in high-dimensional problems with many irrelevant attributes.

Applications

  • Unsupervised outlier and anomaly detection in numeric data.
  • Screening high-dimensional datasets where no labelled anomalies exist.
  • Data-quality checks and exploratory detection of irregular records.
  • Prioritising unusual observations for manual review before further modelling.

How it works

How it works

1

Isolation Forest reverses the usual logic of outlier detection. Instead of building a profile of normal points and flagging whatever deviates from it, it directly exploits the fact that anomalies are few and different and therefore quicker to isolate. Because it needs no labelled anomalies, it is fully unsupervised, and the original evaluation reports good performance on high-dimensional data with many irrelevant attributes.

2

The method builds many random partitioning trees. In each tree the data is recursively split by choosing a feature at random and a random split value, carving the space into smaller and smaller regions until every point sits alone. Isolating a normal point, buried in a crowded region, requires many such partitions, while an anomaly out on its own is separated after only a few.

3

Each point's path length, the number of splits needed to isolate it, is averaged across the forest to give E(h(x)) and converted into an anomaly score through the normalised formula above. Here c(n) is the average path length of an unsuccessful search in a binary search tree built on n points, where n is the sub-sample size used to grow each tree. Scores close to 1 indicate likely anomalies, because their average path lengths are short. Lower scores indicate likely normal points, and intermediate scores are ambiguous. The score alone does not fix a cut-off: to decide which points are flagged, a threshold must be chosen, and many software implementations let the user supply an expected proportion of anomalies (a contamination value) for this purpose.

Formula
s(x) = 2^{-\frac{E(h(x))}{c(n)}}

Common pitfalls

  • Running it on a very small dataset and trusting the flagged points without checking them.
  • Setting a contamination value without any evidence of how many anomalies the data actually contains.
  • Reading anomaly scores as probabilities rather than as a relative ranking.
  • Comparing raw scores across datasets of different sizes, since the normalising term c(n) depends on the sample size.

Frequently asked questions

Do I need labelled anomalies to use Isolation Forest?

No. It is an unsupervised method that isolates anomalies through random partitioning, so it needs no labelled anomaly data to operate.

What does the contamination parameter do?

In many implementations it is the expected proportion of anomalies, and it is used to set the score threshold that decides which points are flagged. It is not part of the original score definition, and it has to come from domain knowledge; if the data contain few genuine anomalies, a chosen value may not be meaningful.

Should I trust Isolation Forest results on small samples?

The original paper does not evaluate small samples, so how reliable the method is on small datasets is unverified. Flagged points on small samples should be checked carefully against domain knowledge before any conclusions are drawn.

How are anomalies scored?

Each point's average path length across the random trees, meaning how many splits it took to isolate, is converted into an anomaly score. Short average paths indicate likely anomalies; long paths indicate likely normal points.

Related methods

Sources

  1. Liu, F.T., Ting, K.M. & Zhou, Z.-H. (2008). Isolation Forest. IEEE ICDM, 413–422.

    Open DOI reference