Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Surprise as a signal
If you know a train usually arrives at 8:02, a train at 8:30 is surprising. A forecasting-based detector works the same way: it predicts the next value and raises an alarm when the real value is too far from the prediction. A sharper prediction makes smaller surprises visible. But if the timetable is updated every time a train is late, a lasting delay soon stops looking surprising.
NASA’s Telemanom system (2018) used exactly this idea: an LSTM forecasts spacecraft telemetry, and large forecast errors become alarms.
- 1. A forecasting-based detector flags values that…
- 2. A better forecaster makes it possible to detect…
- 3. A forecaster that adapts quickly may…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Residual score: e_t = y_t − ŷ_t|t−1, standardised by the sd of residuals on normal data. Large |e_t| means surprise.
- Forecasters: seasonal profiles, ARIMA, exponential smoothing, state-space models, LSTMs and TCNs; any model of normal behaviour will do.
- Thresholds: set from a target false-alarm rate on normal validation data (for example the 99.9% quantile of |score|), or from a dynamic, local estimate of the error distribution.
- Whitening: an AR model turns correlated residuals into nearly independent innovations, so a single unusual value is no longer hidden among slowly wandering errors.
- Adaptation: a model that forecasts from recent values follows a level shift, so the residual is large only at the first step; accumulated statistics (EWMA, CUSUM) or a non-adaptive baseline catch persistent changes.
- Prediction intervals: probabilistic forecasts give the threshold directly as a quantile.
- 1. Thresholds are best set from…
- 2. Whitening residuals with an AR model makes them…
- 3. Persistent shifts are caught better by…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Profile and AR forecasters
Exercise 1.
- Hourly data with a daily cycle and AR(1) noise (φ = 0.8, innovation sd 0.5), 60 days for training.
- Forecaster 1: per-hour median profile. Forecaster 2: profile plus an AR(3) model of the profile residual.
- Thresholds at the 99.9% quantile of |score| on validation data; a spike of 2 added to a test week.
Practice.
- Fit the forecaster on clean normal data, or use robust fitting, so anomalies do not become part of normal behaviour.
- Calibrate thresholds on separate validation data at the false-alarm rate operators can tolerate.
- Combine a fast adaptive detector for spikes with an accumulating or non-adaptive one for shifts.
- Watch forecast quality over time; a degraded model causes false alarms.
- Tools: Merlion (forecast-based detectors), statsmodels, Prophet for profiles, Kats, Telemanom.
import numpy as np
def residual_scores(y, forecast, sd):
return (y - forecast) / sd
def threshold(val_scores, rate=0.001):
return np.quantile(np.abs(val_scores), 1 - rate)- 1. Forecasters for detection should be fitted on…
- 2. For both spikes and shifts, use…
- 3. NASA's LSTM forecasting detector is called…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why the AR forecaster sees spikes. With profile residuals r_t = φ r_t−1 + ε_t, the profile forecaster’s error is r_t, whose sd is σ/√(1 − φ²) = 0.83 for σ = 0.5 and φ = 0.8. The AR forecaster’s error is ε_t, with sd 0.5. A spike of size m therefore gives a score of about m/0.83 against the profile and m/0.5 against the AR model, so the same false-alarm rate detects spikes 1.7 times smaller.
Why it misses shifts. After the level jumps by δ, the AR forecast is built from shifted values, so the residuals are δ at the first step and then δ(1 − φ) = 0.2δ: the model absorbs the change.
EWMA undoes whitening. An EWMA with weight λ of the innovations, s_t = λε_t + (1 − λ)s_t−1, with λ = 1 − φ is exactly λ r_t, a multiple of the profile residual. In Exercise 2 the EWMA (λ = 0.2) of AR residuals behaved like the profile detector, within 0.05 in recall everywhere.
- 1. Profile residual sd for σ = 0.5 and φ = 0.8:
- 2. After a shift δ the AR(1) residuals settle at…
- 3. An EWMA of innovations with λ = 1 − φ equals…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.For spikes and for persistent level shifts of different sizes, which score detects more: residuals from a seasonal profile, from a profile-plus-AR forecaster, or an EWMA of the AR residuals?
History.
- W. A. Shewhart (1920s) introduced control charts on raw measurements; S. W. Roberts (1959) introduced the EWMA chart.
- Residual-based monitoring of autocorrelated processes (L. C. Alwan and H. V. Roberts, 1988) applied charts to time-series model residuals.
- K. Hundman et al. (2018) used LSTM forecasts with dynamic thresholds on NASA telemetry.
Exercise 2.
- Train on 60 days; set each threshold at the 99.9% quantile of |score| on 120 further days of normal data.
- 200 test weeks per setting, with an anomaly at hour 72: a spike of 1, 2 or 3 at one point, or a level shift of 0.5, 1 or 2 lasting to the end.
- A spike counts as found if its own score crosses the threshold; a shift if the score crosses within 48 hours of onset.
Seed 0, recall:
| score | spike 1 | spike 2 | spike 3 | shift 0.5 | shift 1 | shift 2 |
|---|---|---|---|---|---|---|
| profile residual | 0.03 | 0.20 | 0.68 | 0.20 | 0.58 | 0.98 |
| profile + AR residual | 0.23 | 0.85 | 1.00 | 0.14 | 0.33 | 0.92 |
| EWMA of AR residual | 0.03 | 0.20 | 0.69 | 0.20 | 0.58 | 0.98 |
- For spikes the AR residual won clearly: 0.85 against 0.20 for a spike of 2.
- For shifts the profile residual was better: 0.58 against 0.33 for a shift of 1. The AR detector found shifts only at the first step (median delay 0 h) or not at all; the profile detector took a median 15 h for a shift of 1.
- The EWMA matched the profile detector, as the theory predicts.
- Seeds 1 and 2: spike of 2, profile 0.12 and 0.20 against AR 0.67 and 0.83; shift of 1, profile 0.23 and 0.35 against AR 0.15 and 0.28. The thresholds varied between seeds (profile 3.0 to 3.7), which moved the shift results most.
Forecasting-based detection in practice
- Deep forecasters: LSTMs, TCNs and transformers replace AR models for complex multivariate telemetry; the detection logic stays the same.
- Dynamic thresholds: thresholds from recent error statistics adapt to changing noise; see spacecraft telemetry later in this section.
- Combining scores: run a one-step residual test for spikes alongside CUSUM or EWMA on raw deviations for shifts, and calibrate the combined false-alarm rate.
- Retraining: after a confirmed lasting change, refit the model so the new normal is not flagged forever.
References
- K. Hundman, V. Constantinou, C. Laporte, I. Colwell and T. Soderstrom (2018). “Detecting spacecraft anomalies using LSTMs and nonparametric dynamic thresholding.” KDD.
- S. W. Roberts (1959). “Control chart tests based on geometric moving averages.” Technometrics.
- L. C. Alwan and H. V. Roberts (1988). “Time-series modeling for statistical process control.” Journal of Business and Economic Statistics.
- D. C. Montgomery (2019). Introduction to Statistical Quality Control, 8th edition. Wiley.
- A. Blázquez-García, A. Conde, U. Mori and J. A. Lozano (2021). “A review on outlier/anomaly detection in time series data.” ACM Computing Surveys.