Online Isolation Forest

Machine Learning
Introduced by
Tan, S. C.; Ting, K. M.; Liu, T. F. (streaming variant); original iForest by Liu et al.
Year
2008–2011
Type
Streaming anomaly detection (online ensemble)
Family
Machine learning

What does it do?

Online Isolation Forest adapts the Isolation Forest anomaly detector, introduced by Liu, Ting and Zhou (2008), to data that arrives continuously.

Rather than rebuilding all isolation trees when new observations arrive, the forest is updated incrementally so that anomaly scores reflect recent data without reprocessing the full history. It is intended for settings such as real-time monitoring, where the stream is unbounded and its distribution may change.

The intuition behind the method

Isolation Forest scores a point by how quickly random splits separate it from the rest of the data: anomalies tend to be isolated in fewer splits than normal points. In a stream, the difficulty is that the normal distribution may drift, so trees grown on old data can become poorly matched to current observations. The online variant handles this by replacing older trees with trees grown on more recent data as the stream proceeds. The anomaly score, s(x,n) = 2^(−E[h(x)]/c(n)), keeps the form of the batch algorithm, but E[h(x)] is averaged over the current, refreshed set of trees.

History

Isolation Forest was introduced by Liu, Ting and Zhou in 2008 at ICDM as a tree-based detector that isolates anomalies rather than profiling normal points. The online variant described here adapts that batch method by refreshing its trees over time as the stream proceeds, so that scores reflect recent data.

When to use it

Choose Online Isolation Forest when observations arrive continuously, decisions are needed as points arrive, and the normal distribution may drift so that a model fitted once would become stale. It suits tabular data streams such as network records, transaction logs, or sensor readings. No labels are needed to train the forest, and the batch method's evaluation reports good results even when the training data contains no anomalies. Do not use it when the full dataset fits in memory and no real-time decisions are needed; batch Isolation Forest is simpler and avoids choosing an update policy. It is also a poor match when each alert must be justified by explicit rules, because the score comes from an ensemble of random trees rather than from readable criteria.

Limitations and considerations

  • The update policy (window size, which tree to replace, and how often) must be set and tuned; an unsuitable policy either lags behind drift or wastes computation.
  • Trees are grown on a window, so anomalies that arrive in a burst can enter the window and influence the trees built from it, which can reduce their scores. The size of this effect depends on window size and burst length and should be checked on your data.
  • Anomaly masking: a group of similar anomalies close together may take more splits to isolate, which can lower their scores and make them harder to flag.
  • The score is derived from an ensemble of random trees, so explaining a specific alert in terms of readable rules is difficult.
  • Assumptions: the method is unsupervised and assumes that anomalies are a small, sparse minority of the data. The premise that anomalies are isolated more easily than normal points weakens when anomalies are common.

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

Strengths

  • Stores only the current window or reservoir rather than the full stream, so memory use is bounded by the window design.
  • Replacing trees lets the forest follow changes in the normal distribution without a full retrain.
  • Inherits the linear time complexity and low memory requirement reported for the original Isolation Forest.
  • Scores by isolation rather than by modelling a density profile of normal points, so it does not require a density model of the normal class.
  • The anomaly score is continuous, so the alert threshold can be set to trade detections against false alarms.

Applications

  • Real-time network intrusion and cybersecurity event detection.
  • Fraud detection in high-frequency financial transaction streams.
  • Industrial sensor and IoT device anomaly monitoring.
  • Log-stream analysis and operational alerting in large-scale systems.
  • Predictive maintenance by detecting deviations in equipment telemetry.

How it works

How it works

1

An initial forest is built from a fixed-size window of the first arriving observations. Each tree is grown on a random sub-sample of that window, as in the batch method, which keeps time and memory costs low. Within each tree, a random attribute and a random split value are selected recursively, so that anomalous points are separated in fewer splits than normal ones. This forest is the starting detector before streaming updates begin.

2

For each incoming point x, the average path length E[h(x)] across the current trees is computed, and the score s(x,n) = 2^(−E[h(x)]/c(n)) is returned, where c(n) is the expected path length for a dataset of size n. Scores near 1 indicate likely anomalies; scores near 0.5 indicate normal observations.

Formula
s(x,n) = 2^{-E[h(x)]/c(n)}
3

After scoring, the oldest tree is replaced with a new tree grown on a random sub-sample of a recent sliding window or reservoir sample of observations. Because only the window or reservoir is stored rather than the full stream history, memory use stays bounded while the forest tracks drift. The replacement rate is a design choice: refreshing too rarely lets the forest lag behind drift, and refreshing too often adds computation.

4

Incoming points are flagged when their score exceeds a decision threshold chosen for the application. Scores near 1 indicate likely anomalies and scores near 0.5 indicate normal observations, so the threshold lies above the normal range and must be calibrated on labelled or expert-reviewed examples for the false-positive rate that can be accepted. Because the score distribution can shift as the stream drifts, the threshold should be revisited periodically.

Common pitfalls

  • Setting the replacement rate too high wastes computation; setting it too low lets the forest fail to track distribution drift.
  • Judging the detector by accuracy on normal points alone. The false-positive rate and the detection rate on known anomalies should be reported, since alert volume is what operators experience.
  • Ignoring concept drift and running a static batch forest on a stream, which can lead to silent performance decay as the normal distribution moves.
  • Deploying without validating the score threshold on held-out labelled examples.
  • Applying the detector to categorical or mixed-type features without encoding them. The behaviour of random splits on such features is not established for this method, so encode them and validate the scores on your own data.

Frequently asked questions

How is Online Isolation Forest different from standard Isolation Forest?

Standard Isolation Forest is trained once on a fixed batch of data and cannot adapt to new observations. Online Isolation Forest incrementally updates the tree forest as new data arrives, allowing it to track distribution changes in a stream without full retraining.

How do I choose how often to refresh the trees?

A common strategy is to replace the oldest tree with a new one grown on a recent window of data every time a fixed number of new observations arrive. The replacement rate should be calibrated against the expected speed of distribution drift in your application.

Does Online Isolation Forest work well on high-dimensional data?

The original Isolation Forest paper reports good performance on high-dimensional problems with many irrelevant attributes. Whether the streaming variant behaves the same way depends on how your implementation handles windows and features, so validate it on your own data. Feature selection may still help.

What anomaly score threshold should I use?

No single threshold is correct across datasets. Scores near 1 indicate likely anomalies and scores near 0.5 indicate normal observations, so the operating threshold is chosen between these regimes. Calibrate it on labelled validation examples, or against an acceptable false-positive rate, before deployment, and revisit it if the score distribution shifts.

Can it handle concept drift?

That is the design aim of the method. Replacing older trees with trees grown on recent data lets the model follow gradual or sudden changes in the normal distribution, although how quickly it adapts depends on the replacement policy.

Related methods

Sources

  1. Liu, F. T., Ting, K. M., & Zhou, Z.-H. (2008). Isolation Forest. In Proceedings of the 8th IEEE International Conference on Data Mining (ICDM), pp. 413–422.

    Open DOI reference
  2. Tan, S. C., Ting, K. M., & Liu, T. F. (2011). Fast Anomaly Detection for Streaming Data. In Proceedings of the 22nd International Joint Conference on Artificial Intelligence (IJCAI), pp. 1511–1516.

    Open publication reference