Robust random cut forest

Also known as: RRCF

On this page 7

A robust random cut forest (RRCF) is an unsupervised, tree-based ensemble for anomaly detection that builds random partition trees over a sample of data and scores each point by its collusive displacement, the amount by which removing the point would shrink the description of the trees. It was designed for streaming data: points can be inserted and deleted from the trees incrementally while the forest keeps a statistically consistent model.

The method extends the idea behind isolation forests with two changes: cut dimensions are chosen in proportion to the range of each feature, and the score accounts for groups of anomalies that hide one another. These properties make RRCF a common choice for real-time monitoring of metrics, sensors and transactions.

How a random cut tree partitions data

A random cut tree recursively splits a set of points until every point sits in its own leaf. At each node, the algorithm computes the bounding box of the points, picks a dimension with probability proportional to its side length, and draws a cut value uniformly within that range. Points on each side of the cut form the two child nodes.

Range-weighted selection is the main difference from an isolation tree, which picks dimensions uniformly. Weighting by range means that irrelevant low-variance features are rarely chosen, while features where a point lies far from the rest are cut often. An outlying point is therefore separated near the root, at a shallow depth.

The following table lists the parameters that control a forest and their typical values.

ParameterTypical valueEffect
Number of trees50 to 200More trees reduce score variance
Tree size (sample)256 to 1,024 pointsLarger samples capture rarer normal modes
Shingle size1 to 48 consecutive valuesCaptures temporal patterns in time series
Sampling rateReservoir or sliding windowControls how fast the model forgets
Score thresholdSet from score distributionConverts scores into alerts
Main RRCF parameters

Collusive displacement as the anomaly score

RRCF scores a point by asking how much the model complexity changes if the point is removed. Complexity is measured as the sum of leaf depths across the tree. Removing an ordinary point inside a dense cluster barely changes the tree; removing an outlier deletes a branch near the root and shortens the paths of many other points. This change is called displacement.

Plain displacement fails when several anomalies arrive together, because they shield one another inside a shared subtree. Collusive displacement, abbreviated CoDisp, therefore considers every subtree containing the point and takes the maximum ratio of displacement to subtree size. A small cluster of identical fraudulent transactions still receives a high anomaly score, which addresses the masking problem.

The forest score is the average CoDisp across trees. Scores are unitless and relative, so the decision threshold is usually set from the empirical score distribution, for example the 99.5th percentile over a calibration window, rather than from a fixed constant.

Streaming updates without retraining

The key engineering property of RRCF is that insertion and deletion produce a tree with the same distribution as one built from scratch on the updated sample. Insertion walks down the tree and places a new cut where the point would have been separated; deletion removes the leaf and splices the sibling into the parent. Both operations cost roughly logarithmic time in the tree size.

As a result, a forest can maintain a sliding window or a reservoir sample of recent data indefinitely. Each new observation is scored, inserted, and an old observation is evicted. This makes the method suitable for concept drift, where normal behavior changes slowly over weeks or seasons.

The table below summarizes the streaming workflow per incoming point.

StepOperationPurpose
ShingleCombine the value with recent valuesRepresent local temporal shape
ScoreCompute average CoDisp across treesMeasure how unusual the point is
InsertAdd the point to each sampled treeKeep the model current
EvictDelete the oldest or a random pointBound memory and forget old regimes
AlertCompare the score with a thresholdTrigger investigation or automation
Per-point streaming cycle

RRCF belongs to the family of isolation-based detectors, yet its streaming design and score definition set it apart. The comparison below covers neighbors from the same topic.

MethodScore basisStreaming supportMain weakness
Robust random cut forestCollusive displacementNative insert and deleteSensitive to feature scaling
Isolation forestAverage path lengthRequires periodic retrainingUniform cuts waste splits
Extended isolation forestPath length with oblique cutsRequires retrainingHigher cost per split
Local outlier factorLocal density ratioCostly incremental versionsNeighbor search scales poorly
Autoencoder detectionReconstruction errorNeeds retraining or fine-tuningNeeds more data and tuning
RRCF and neighboring methods

In practice, RRCF is chosen when latency and adaptivity matter more than the last few points of accuracy, such as in operational dashboards. Batch problems with stable data are often served equally well by an isolation forest.

Limitations and common mistakes

Because cut probability depends on feature ranges, RRCF is not scale invariant. A feature measured in milliseconds will dominate one measured in seconds unless the data is normalized first. Other frequent issues are listed below.

  • Too small a tree size makes rare but normal patterns, such as weekend traffic, look anomalous.
  • Wrong shingle length misses periodic anomalies; it should cover at least one meaningful cycle fragment.
  • Fixed thresholds break under drift; recalibrate from recent score quantiles.
  • High-dimensional noise dilutes cuts across irrelevant features, so feature selection still matters.
  • Scores lack explanation by default, although per-dimension attribution of displacement can be computed.

In simple terms

Imagine cutting a pile of points with random straight lines. Points in a crowd need many cuts before each stands alone. A point far from the crowd is cut off almost at once.

A robust random cut forest repeats this cutting in many trees. It then asks a simple question for each new point. How much simpler would the trees be without it? If the answer is much simpler, the point is probably unusual. The forest also updates itself as new data arrives. It learns the new normal without starting over.

A practical example

An online retailer monitors the number of checkout requests per minute on its payment service. The operations team feeds each one-minute value into a robust random cut forest with 100 trees, a tree size of 512 points and a shingle size of 10, so each point represents the last ten minutes of traffic.

During normal days, scores stay low, and the evening peak is learned as ordinary because the sliding window contains several weeks of history. One night, traffic drops by about 40 percent within three minutes while a payment gateway fails silently. The CoDisp score jumps above the 99.5th percentile threshold on the second affected minute, and an alert reaches the on-call engineer.

The team restores the gateway within minutes. Because RRCF flagged the shape of the drop rather than a fixed level, the same configuration continues to work during holiday sales, when absolute traffic is several times higher.