Skip to content

Isolation Forest vs the Humble Z-Score

Isolation Forest vs a z-score on the UCR and NAB anomaly benchmarks, why point adjusted F1 is left out and how the winner changes with data.

On this page

The z-score has been doing this quietly for a very long time. Take the recent past, ask how many standard deviations away the new point sits, raise a hand if the answer is large. Before I let an Isolation Forest replace that, I wanted to see the two of them sit the same exam, with the same marking.

The exam is the benchmark harness in Sentinel-ML, an anomaly detection project for infrastructure metrics that I started in October 2026.

The marking scheme comes first

Much published work on time series anomalies reports scores after a step called point adjustment. If a detector flags even one point inside a labelled anomaly, the whole stretch counts as detected. A detector that shouts at random will, sooner or later, shout somewhere inside a long anomaly and collect the lot. Kim and colleagues showed that under point adjustment even a random anomaly score can look like the state of the art.

Here is the trick in one picture.

title="sketch of point adjustment, each mark is a point in time"text
labelled anomaly    . . # # # # # # . .
what was flagged    . . . . . # . . . .
after adjustment    . . # # # # # # . .

One hit, six points of credit. So it is excluded here, entirely. Quality is measured with range-based precision and recall, which gives credit for how much of an anomaly was covered and takes it away for fragmenting the alert into pieces. Beside it sit the number of series detected, the delay from the start of an anomaly to the first hit, and false positive ranges, meaning predicted stretches that touch no labelled point.

The numbers will look small. They are supposed to.

The contestants

  • Static threshold: distance from the median of the training data.
  • Rolling z-score: distance from the recent mean in units of recent spread, over the previous 100 points.
  • EWMA: the same idea with an exponentially weighted memory, smoothing factor 0.1.
  • Isolation Forest: 100 random trees over windows of 32 points. The intuition is that unusual samples get separated by random splits in fewer steps.

Every detector scores a point using only what came before it. Each one sets its own alert level from the training portion alone, by fitting on the first half and looking at the second. No test data, no labels.

Comparing at matched recall

Default alert levels make an unfair comparison, since a detector can look quiet simply by catching less. So each detector also gets one global adjustment, chosen to be as strict as possible while still reaching the same average recall as the z-score at its default. Then the false positives are counted.

So every table below reads the same test scores in one of two ways.

flowchart TD
    S[Scores on the test stream] --> D["Default: alert level from training"]
    S --> M["Matched: one adjustment per detector"]
    D --> A["F1, series detected, delay, false positives"]
    M --> B["False positives at the z-score's recall"]

Isolation Forest vs z-score on UCR

The UCR Anomaly Archive was introduced by Wu and Keogh in a paper arguing that popular benchmarks are flawed. It has 250 series, each with exactly one labelled anomaly.

Range F1, series detected and delay come from each detector’s own default.

UCR, at defaultRange F1Detected of 250Median delay
Static threshold0.0284143
Rolling z-score0.0364521
EWMA0.0303523
Isolation Forest0.0445489.5
Ensemble of baselines0.0424732
Ensemble with forest0.0475332

Delay is counted in points. Now the false alarms, both ways.

UCR false positives per 10kMatchedDefault
Static threshold4.974.71
Rolling z-score3.763.76
EWMA9.553.01
Isolation Forest2.978.06
Ensemble of baselines2.003.96
Ensemble with forest1.435.80

At matched recall the forest produces fewer false alarms than the z-score, 2.97 against 3.76. At its own default it produces more than twice as many, 8.06 against 3.76. At that default it also finds more series and takes over four times as long to speak up. Which of those is “better”? It depends on whether your pager hates noise or hates waiting.

A random forest invites one obvious objection: lucky seed. So it ran five times.

xychart-beta
    title "UCR matched false positives per 10k, forest by seed"
    x-axis ["seed 0", "seed 1", "seed 2", "seed 3", "seed 4"]
    y-axis "bars: forest, line: z-score" 0 --> 4
    bar [2.97, 3.06, 2.72, 2.84, 2.71]
    line [3.76, 3.76, 3.76, 3.76, 3.76]

Every bar stays under the line, from 2.71 to 3.06 against 3.76. The false positive win holds in all five. Now the same five runs on the other measures.

Forest seedRange F1Series detected
00.04454
10.03747
20.03853
30.03745
40.03345

The range F1 win does not survive nearly as well: the mean is about 0.038 against the z-score’s 0.036, one seed falls below it and two more barely clear it. Seed 0, the one in the headline table, is the best of the five on F1 and series detected. Had I stopped there, the forest would have looked better than it is. Five seeds is not a confidence interval either.

On NAB the lead evaporates

The Numenta Anomaly Benchmark brings timestamped streams, so false positives can be counted per day. 54 series ran, 49 with labels.

NAB, at defaultRange F1Detected of 49Median delay
Static threshold0.1934471.5
Rolling z-score0.14436100
EWMA0.12736100
Isolation Forest0.1664343
Ensemble of baselines0.14035100
NAB false positives per dayMatchedDefault
Static threshold1.051.94
Rolling z-score0.5950.595
EWMA0.820.53
Isolation Forest0.5863.25
Ensemble of baselines1.921.96

Matched, the forest and the z-score are level: 0.586 against 0.595 per day, about 1.5 percent apart on a single fit with no seed sweep. At defaults the forest is more than five times as noisy, while catching more and catching it sooner. The delay story from UCR has flipped.

The ensemble flips harder. Second best row on UCR at matched recall, worst row on NAB, behind every single detector. Why does taking the loudest of several detectors help on one suite and hurt on the other? I have not investigated, so I will not guess in print.

The same suite, fewer series

Adding the forest to the ensemble meant a second NAB run with all six detectors, and only 41 series came through it, 36 of them labelled. It is not comparable row for row with the table above, and it is worth showing precisely because of what changes:

Detector, smaller NAB setFalse positives per day, matchedDetected of 36
Rolling z-score0.6925
Isolation Forest0.3334
Ensemble of baselines2.0825
Ensemble with forest0.5627

Put the forest and the z-score from both selections side by side.

xychart-beta horizontal
    title "NAB matched false positives per day, two series sets"
    x-axis ["z-score, 54 series: 0.595", "Forest, 54 series: 0.586", "z-score, 41 series: 0.69", "Forest, 41 series: 0.33"]
    y-axis "lower is better" 0 --> 1
    bar [0.595, 0.586, 0.69, 0.33]

Here the forest halves the z-score’s false alarms. On the larger set they tied. Same code, same suite, a different selection of streams, and the headline would flip from “no real difference” to “twice as good”. The forest also drags the ensemble a long way down in false alarms, and the result is still noisier than the forest on its own. If someone quotes you one number from one subset, ask which series produced it.

The verdict

The project’s rule is that a learned detector becomes a default only if it beats the baselines across the suite on false positives at matched recall. A clear win on one suite, with the other tied or ahead depending on which series ran, has not settled that yet, and two further suites are still pending. The forest and the ensembles stay opt-in. The losing rows stay in the tables.

The z-score, meanwhile, was the quickest to detect on UCR, stayed level with the forest for the fewest false alarms on the larger NAB set, and fits in a few lines. It has not asked for a promotion.