Forecasting-based anomaly detection

Also known as: prediction-based anomaly detection

On this page 7

Forecasting-based anomaly detection is a time series technique that trains a model to predict the expected next values of a signal and flags an observation as anomalous when the prediction error is larger than normal variation explains. In anomaly detection, it is also called prediction-based anomaly detection, and it is one of the most widely used approaches for monitoring metrics, sensors and business data streams.

The idea is simple: a good forecaster captures trend, seasonality and short-term dynamics, so whatever it cannot predict is suspicious. The quality of detection therefore depends on two parts working together, an accurate forecasting model and a well-calibrated threshold on the residuals.

How prediction errors reveal anomalies

The method works in a forecast, compare, score and decide cycle. At each time step the model uses a window of past values to produce a forecast, the actual value arrives, and the difference between them becomes the raw evidence of abnormality.

  1. Fit a forecaster on historical data that is mostly normal.
  2. Predict the next value or the next h values from a sliding context window.
  3. Compute the residual, the difference between the observed and predicted value.
  4. Convert the residual into an anomaly score, often by dividing by the expected error spread.
  5. Apply a threshold and raise an alert when the score exceeds it.

Normalization is essential because error size changes with context. A deviation of 50 requests per second is negligible at peak traffic and alarming at night. Probabilistic forecasters solve this by producing a predictive distribution, so a point can be flagged when it falls outside a prediction interval, for example the 99 percent interval.

The forecast horizon also shapes behavior. One-step-ahead forecasts react quickly and suit spikes, while multi-step forecasts compared against a whole window reveal gradual deviations that single-point residuals miss. Using the observed value to update the model immediately keeps it current, but it lets a long anomaly pull the forecast toward itself and fade from view.

Forecasting models used for detection

Almost any forecaster can serve as the backbone, and the choice should match the structure of the series. Simple statistical models are often stronger baselines than expected, especially on short or noisy data.

Model familyCaptures wellWeakness for detection
Exponential smoothingLevel, trend and seasonalitySlow to handle regime changes
ARIMA and SARIMAAutocorrelation, seasonal cyclesAssumes linear dynamics
Prophet-style decompositionHolidays, multiple seasonalitiesWeak on short-term dynamics
LSTM and GRU networksNonlinear and multivariate patternsNeeds much data and tuning
Temporal convolution and transformersLong context, many related seriesCostly, can overfit anomalies
Gradient-boosted trees on lagsMixed features, calendar effectsNo native uncertainty estimate
Common forecasting models and their fit for detection

In multivariate settings such as spacecraft telemetry, a common design trains one forecaster per channel and scores each residual separately, which keeps alerts explainable. Joint models capture cross-channel relations but make it harder to identify which signal caused the alert.

Scoring and thresholding the residuals

The threshold decides the trade-off between missed anomalies and false alarms. Residuals are rarely Gaussian, they change over time and they are autocorrelated, so a static three-sigma rule often generates alert storms or silence.

StrategyHow it worksWhen it fits
Static sigma ruleAlert when residual exceeds k standard deviationsStable, near-Gaussian errors
Prediction intervalAlert when value leaves a quantile bandProbabilistic forecasters
Rolling quantileThreshold from recent residual quantilesSlowly drifting error levels
Dynamic thresholdingSmoothed errors and an adaptive cutoffNoisy telemetry, many channels
Extreme value theoryFit a tail distribution to large errorsRare events, strict false-alarm targets
Thresholding strategies for forecast residuals

Many systems also smooth errors over a short window before thresholding, which suppresses single-point noise, and require several consecutive exceedances before alerting. This adds detection delay in exchange for fewer false positives, a choice that should follow the cost of each error type.

Comparison with other time series detectors

Forecasting-based detection is strongest for point and contextual anomalies in signals with predictable structure. Other families of time series anomaly detection look at the data differently, and production systems frequently combine them.

ApproachCore signalBest at detecting
Forecasting-basedOne-step or multi-step prediction errorSudden spikes, broken seasonality
Reconstruction-basedAutoencoder reconstruction errorAbnormal window shapes
Matrix profileDistance to the nearest similar subsequenceUnusual subsequences, discords
Change point detectionShift in distribution parametersPersistent level or variance shifts
Seasonal hybrid ESDRobust decomposition plus statistical testOutliers in seasonal metrics
Forecasting compared with related approaches

A practical advantage of forecasting is interpretability: an operator can see the expected value next to the observed one. A practical weakness is that a sustained shift is soon absorbed by an online model, so level changes are better handled by change point detection.

Pitfalls and design decisions

The most damaging pitfall is training on contaminated history. If past incidents remain in the training data, the model learns to forecast them and later anomalies of the same kind produce small residuals.

  • Clean or down-weight known incidents before fitting, or use robust loss functions.
  • Avoid an overly powerful forecaster that follows anomalies too closely, which hides them.
  • Retrain on a schedule so that legitimate drift does not become a stream of false alerts.
  • Evaluate with event-level metrics and detection delay, not only point-wise precision and recall.
  • Model known calendar effects such as holidays, releases and campaigns as inputs.

Benchmarks such as the Numenta Anomaly Benchmark reward early detection, which shows that timing matters as much as accuracy. A detector that is right but late may have little operational value.

A non-technical view

Think of a shop owner who knows that about 40 customers arrive every Monday morning. If 41 come, nothing is wrong. If only 3 come, something unusual is happening.

Forecasting-based anomaly detection does the same with data. A computer learns the usual pattern and guesses the next number. When the real number is far from the guess, it raises an alarm. The hard part is deciding how far is too far, so that people get warned about real problems and not about every small wobble.

A concrete example

A regional electricity distributor monitors load on 1,200 substations every 15 minutes. Each substation gets a seasonal forecasting model that uses the previous two weeks of readings, the time of day, the weekday and the local temperature forecast.

The system compares each new reading with a 99 percent prediction interval. It raises an alert only when three consecutive readings fall outside the band, which keeps the false alarm rate below about two alerts per day across the network.

One winter night, a substation in a residential area shows load 35 percent above its forecast while the temperature stays normal. Engineers find an unauthorized connection to the grid that had begun that evening. The forecasting approach caught it within 45 minutes, whereas the old fixed capacity alarm would have triggered only after the load reached its physical limit.