Foundations to Frontier
Tests
K. Time Series and Sensor Data › K3 Anomaly and Change Detection

Point, contextual and collective anomalies

An anomaly is an observation or pattern that does not fit the normal behaviour of the data. In time series there are three kinds: point anomalies (a single extreme value), contextual anomalies (a value that is normal in general but not at that time) and collective anomalies (a stretch whose values are ordinary one by one but abnormal together). This page builds one simple robust detector for each kind and measures which detector finds which anomaly, and at what cost in false alarms.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Three ways to be strange

A heart-rate sensor reading 250 is strange on its own: a point anomaly. A reading of 120 is fine during a run but strange at 3 a.m. while asleep: a contextual anomaly. A reading that stays at exactly 70 for an hour is made of normal values, but no living heart is that steady: a collective anomaly. Each kind needs a different kind of check.

Anomaly lab
A spike at hour 60, daytime values at night (hours 113–115) and two noiseless days (168–215). Dots under the plot: global robust z, per-hour profile, rolling variability, each at |z| > 4. Found — spike: no / yes / no; night values: no / yes / no; noiseless days: no / no / yes. Flags elsewhere: 0 / 5 / 0.
Why engineers care

A sensor that freezes and keeps reporting its last value is one of the most common faults in industrial data, and simple range checks never catch it.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A value that is normal in general but wrong for its time is…
  2. 2. A frozen sensor reading is usually…
  3. 3. A single extreme spike is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Point anomaly: a single observation far from the rest of the data (a glitch, a spike).
  • Contextual anomaly: an observation that is abnormal given its context, such as time of day, season or operating mode, but not in the overall distribution.
  • Collective anomaly: a subsequence that is abnormal as a whole: a frozen sensor, a missing cycle, a change in variability or shape.
  • Robust statistics: the median and the median absolute deviation (MAD; 1.4826·MAD estimates the sd for Gaussian data) are not pulled by the anomalies themselves, unlike the mean and sd (masking).
  • Context: compare each value with a seasonal profile (for example the per-hour median), a forecast or similar operating conditions.
  • Scoring: event-level recall (was the event flagged at all) and false alarms per unit time matter more to operators than point-level accuracy.
📝 Quick check (Level 1)
0/3 answered
  1. 1. 1.4826·MAD estimates…
  2. 2. Masking happens when…
  3. 3. Contextual anomalies need…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

One detector per kind

Exercise 1.

  • Thirty days of hourly data with a daily cycle, with one anomaly of each kind injected: a glitch to 10 ± 25–30, three night hours set to daytime values, and two days where the noise vanishes.
  • Detectors: a global robust z-score, a robust z-score of the residual from the per-hour median profile, and a robust z-score of the log rolling variability of that residual.
  • Each anomaly is found only by the detectors designed for its kind.

Practice.

  • Remove known structure first (seasonality, operating mode), then look for anomalies in the residual.
  • Use robust location and scale so the anomalies do not hide themselves.
  • Run several detectors for different kinds and combine their flags, watching the total false-alarm rate.
  • Score at the event level and agree on how early or late a flag still counts.
  • Tools: PyOD, Merlion, ADTK (rule-based detectors for time series), Kats.
import numpy as np

def robust_z(x):
    m = np.median(x)
    return (x - m) / (1.4826 * np.median(np.abs(x - m)))
🐍 Exercise 1: three anomalies, three detectors
Inject a point, a contextual and a collective anomaly into hourly seasonal data and show which of three robust detectors finds each.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Before searching for anomalies in seasonal data, remove…
  2. 2. Combining several detectors increases…
  3. 3. A Python library of rule-based time-series detectors:

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Breakdown point. The mean and sd can be moved arbitrarily by a single value: their breakdown point is 0. The median and MAD have breakdown point 50%: more than half the data must be corrupted to move them arbitrarily. In p1 a value of 60 among 51 others pushed the ordinary z-score of a value of 6 down to 0.56, while its robust z-score stayed 5.6.

Thresholds and false alarms. For independent Gaussian noise, a threshold |z| > k flags a fraction 2(1 − Φ(k)) of normal points: 2.7 per 1000 for k = 3 and 0.063 per 1000 for k = 4. Real residuals are autocorrelated and heavier-tailed, and many detectors are combined, so observed rates are higher. In Exercise 2 the three detectors together gave 4.4 false alarms per 1000 normal points at k = 4.

Why collective anomalies need a window. Each value of a frozen or noise-free stretch lies well inside the normal range, so no per-point test can flag it. A statistic over a window, here the sd of differences, changes as a whole and can be tested instead.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Breakdown point of the median:
  2. 2. Fraction of Gaussian points with |z| > 3:
  3. 3. Collective anomalies are found with…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

When anomalies vary in strength, how often does each detector find each kind, and what does lowering the threshold cost in false alarms?

History.

  • F. E. Grubbs (1969) gave a classic test for outliers; F. R. Hampel (1974) introduced the influence function and robust scale estimates such as the MAD.
  • V. Chandola, A. Banerjee and V. Kumar (2009) popularised the classification into point, contextual and collective anomalies.
  • Benchmarks such as Numenta (NAB, 2015) and later critiques (R. Wu and E. Keogh, 2021) showed how much evaluation choices matter.

Exercise 2.

  • 200 series of 30 days of hourly data, each with one anomaly of each kind at random strength.
  • Point: a spike of ±1–12 added to the expected value. Contextual: 3 night hours moved a random 10–100% of the way to daytime values. Collective: 48 hours whose noise is shrunk to 0–60% of normal.
  • An event counts as found if any point inside it is flagged (12 steps of slack for the window detector and the combination). False alarms are counted on points at least 12 steps from any event.

Seed 0, threshold k = 4:

detector point contextual collective false alarms per 1000
global robust z 0.00 0.00 0.00 0.0
per-hour profile 0.91 0.90 0.00 0.4
rolling variability 0.74 0.72 0.75 4.0
all three 0.91 0.91 0.76 4.4
  • The global detector found nothing: the daily cycle makes the overall spread so large that spikes up to 12 stay inside it.
  • The per-hour profile found about 90% of point and contextual anomalies with very few false alarms, but never a collective one.
  • Only the rolling-variability detector found collective anomalies; it also fires on spikes and shifts, and causes most of the false alarms.
  • Threshold trade-off for the combination: k = 3 found 0.965, 0.945 and 0.98 with 14.5 false alarms per 1000; k = 5 found 0.815, 0.83 and 0.535 with 3.2.
  • Seeds 1 and 2: at k = 4 the per-hour profile found 0.92 and 0.91 of point anomalies, and the rolling detector 0.82 and 0.8 of collective ones; the combination gave 4.2 false alarms per 1000 in both.
🐍 Exercise 2 (research): when anomalies vary in strength, how often does each detector find each kind, and what does lowering the threshold cost in false alarms?
Inject graded point, contextual and collective anomalies into 200 hourly series and measure event recall and false alarms for a global, a per-hour-profile and a rolling-variability detector at thresholds 3, 4 and 5.

Anomaly types in practice

  • Industrial monitoring: frozen sensors, flatlines and drifting calibration are collective faults; range checks catch only gross point errors.
  • Context variables: operating mode, load and weather are often better context than time of day.
  • Alert fatigue: a few false alarms per 1000 points is many per day on high-frequency data with many channels, so thresholds are set from the tolerable alarm rate.
  • Next topics: forecasting-based and reconstruction-based detectors replace the per-hour profile with a learned model of normal behaviour.

References

  1. V. Chandola, A. Banerjee and V. Kumar (2009). “Anomaly detection: a survey.” ACM Computing Surveys.
  2. F. R. Hampel (1974). “The influence curve and its role in robust estimation.” Journal of the American Statistical Association.
  3. F. E. Grubbs (1969). “Procedures for detecting outlying observations in samples.” Technometrics.
  4. A. Lavin and S. Ahmad (2015). “Evaluating real-time anomaly detection algorithms: the Numenta anomaly benchmark.” IEEE ICMLA.
  5. R. Wu and E. Keogh (2021). “Current time series anomaly detection benchmarks are flawed and are creating the illusion of progress.” IEEE Transactions on Knowledge and Data Engineering.