Skip to content
AI360XpertBeta
Core ML

Visual explainer

Anomaly Detection

Score unusual observations against a reference, trace isolation and neighbourhood counts, and see how contamination and indistinguishable inputs defeat detection.

A query at 12 sits far beyond the six reference observations.
A query at 12 sits far beyond the six reference observations.

Anomaly detection scores unusual observations relative to a reference. A high score can trigger investigation; it does not establish that an event is harmful. In this synthetic example, filled dots are the reference values 2, 3, 3, 4, 4, 5, and a hollow ring is a query at 12. Duplicate values stack vertically; only horizontal position measures value. All quantities are unitless.

Calibrate the Distance

One standard deviation calibrates distance from the reference mean.
One standard deviation calibrates distance from the reference mean.

This view zooms to 100 drawing units per data unit. The reference mean is 21/6=3.521/6=3.5. Its squared deviations sum to 5.5, so the population variance is 5.5/6=11/125.5/6=11/12 and standard deviation is σ=11/12≈0.9574\sigma=\sqrt{11/12}\approx0.9574. The bracket measures one standard deviation from the mean.

Define the score s(x)=∣x−3.5∣/0.9574s(x)=|x-3.5|/0.9574. Query 12 has score 8.878. These descriptive distances are not calibrated probabilities. A tiny reference does not establish a distribution; NIST's outlier guidance explains why outlier interpretation depends on assumptions and investigation.

Isolate With a Cut

A cut at 8 isolates the query at 12 in one partition.
A cut at 8 isolates the query at 12 in one partition.

Return to the original scale, 38 drawing units per data unit. For this separate partition demonstration, consider the reference and query together. A chosen cut at 8 leaves all six reference observations on the left and only 12 on the right. The singleton's path has length one in this particular tree. Another random cut can produce a different depth.

Isolation Forest repeats recursive random feature splits and averages path lengths across trees. The pictured cut is a valid example, not a guaranteed split count or a computed forest score. Identical reference values cannot be separated using this feature alone.

Count Nearby Observations

A radius of one contains four neighbours of reference 4 and none of query 12.
A radius of one contains four neighbours of reference 4 and none of query 12.

The lower brackets span an inclusive radius of one in data value. Treat one reference 4 as a probe and exclude that probe itself: its interval [3,5] contains the two 3s, the other 4, and 5. Query 12's interval [11,13] contains no reference observation. Vertical stacking has no effect on these one-dimensional distances.

This fixed-radius count illustrates neighbourhood evidence. It is not Local Outlier Factor: LOF compares a point's local density with its neighbours' densities, using nearest-neighbour reachability distances. Neither method guarantees that every rare observation is an error.

Turn Scores Into Alerts

The reference threshold flags query 12 for investigation.
The reference threshold flags query 12 for investigation.

Choose an illustrative rule: flag a query when its score exceeds 2. The upper cutoff is 3.5+2(0.9574)=5.41493.5+2(0.9574)=5.4149; the lower cutoff is 1.58511.5851, outside the displayed reference cluster. Query 12 crosses the upper cutoff. The drawing shows the positive side of an absolute-distance rule, not a one-sided definition of anomalies. Selecting this threshold requires knowledge of alert costs and representative evaluation data.

Change the Workload

Lowering the threshold adds query 5 to the alert set.
Lowering the threshold adds query 5 to the alert set.

Both rows use the same zoom as scene 2. Query 5 has score 1.5/0.9574=1.5671.5/0.9574=1.567: it passes threshold 2 but is flagged by threshold 1. The upper cutoffs move from 5.4149 to 4.4574. This adds alerts, including this value already seen in the reference. We have no outcome labels here, so we cannot calculate precision, false-positive rate, or the best cutoff.

Protect the Reference

Adding 12 to the reference moves the cutoff beyond query 8.
Adding 12 to the reference moves the cutoff beyond query 8.

The two rows return to the original scale. With the clean reference, query 8 has score 4.5/0.9574=4.7004.5/0.9574=4.700 and is flagged. Now deliberately contaminate the reference by adding 12. The new mean is 33/7=4.714333/7=4.7143, population variance is 472/49472/49, standard deviation is 3.1037, and upper cutoff is 10.9216. Query 8 now scores only 1.059 and passes.

The amber cross marks the lost alert. The added filled dot is reference 12; query 8 stays fixed. Estimating location and spread from contaminated data can mask unusual observations. A robust estimator may help under its own assumptions; changing estimators does not establish which events are harmful.

Rank Before Selecting

Scores rank queries before a threshold selects which ones to flag.
Scores rank queries before a threshold selects which ones to flag.

Restore the clean reference. Row labels identify queries 4, 5, 6, and 12. Horizontal bar length measures scores 0.522, 1.567, 2.611, and 8.878 on one scale; the dashed line is threshold 2. Ranking supplies an order even before choosing a cutoff. Thresholding selects the last two queries here. These numbers are scores, not probabilities of fraud.

Predict a Fresh Query

A fresh query at 6 exceeds the unchanged reference threshold.
A fresh query at 6 exceeds the unchanged reference threshold.

Keep the clean mean, spread, and threshold fixed. Before calculating, 6 must be flagged because it lies beyond 5.4149. Its gap from the mean is 2.5, giving score 2.5/0.9574=2.6112.5/0.9574=2.611. The upper bracket measures that gap. Adding the query to the reference first would answer a different question, as scene 7 demonstrates.

Where It Breaks

Identical observed values receive identical scores even when one event is harmful.
Identical observed values receive identical scores even when one event is harmful.

Suppose two events both have observed value 4, but one is legitimate and one harmful for reasons absent from the feature. Both receive score 0.522 and pass. Their displayed positions and cutoffs are identical; the amber cross identifies the missed harmful event using information the detector does not possess. No deterministic detector using only that same input can distinguish them. More representative features or other evidence are needed; rarity alone cannot reveal intent.

The Quick Version

  • Compare queries against a defined reference.
  • Standardize distance using an explicitly chosen spread estimate.
  • Isolation depth depends on the random partition.
  • Fixed-radius counts are not LOF scores.
  • Thresholds turn scores into investigation decisions.
  • Lower thresholds add alerts.
  • Contaminated references can mask unusual queries.
  • Ranking does not choose an alert budget.
  • Score fresh queries without silently refitting the reference.
  • Identical observed inputs cannot reveal different hidden intent.