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.
- Fit a forecaster on historical data that is mostly normal.
- Predict the next value or the next h values from a sliding context window.
- Compute the residual, the difference between the observed and predicted value.
- Convert the residual into an anomaly score, often by dividing by the expected error spread.
- 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 family | Captures well | Weakness for detection |
|---|---|---|
| Exponential smoothing | Level, trend and seasonality | Slow to handle regime changes |
| ARIMA and SARIMA | Autocorrelation, seasonal cycles | Assumes linear dynamics |
| Prophet-style decomposition | Holidays, multiple seasonalities | Weak on short-term dynamics |
| LSTM and GRU networks | Nonlinear and multivariate patterns | Needs much data and tuning |
| Temporal convolution and transformers | Long context, many related series | Costly, can overfit anomalies |
| Gradient-boosted trees on lags | Mixed features, calendar effects | No native uncertainty estimate |
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.
| Strategy | How it works | When it fits |
|---|---|---|
| Static sigma rule | Alert when residual exceeds k standard deviations | Stable, near-Gaussian errors |
| Prediction interval | Alert when value leaves a quantile band | Probabilistic forecasters |
| Rolling quantile | Threshold from recent residual quantiles | Slowly drifting error levels |
| Dynamic thresholding | Smoothed errors and an adaptive cutoff | Noisy telemetry, many channels |
| Extreme value theory | Fit a tail distribution to large errors | Rare events, strict false-alarm targets |
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.
| Approach | Core signal | Best at detecting |
|---|---|---|
| Forecasting-based | One-step or multi-step prediction error | Sudden spikes, broken seasonality |
| Reconstruction-based | Autoencoder reconstruction error | Abnormal window shapes |
| Matrix profile | Distance to the nearest similar subsequence | Unusual subsequences, discords |
| Change point detection | Shift in distribution parameters | Persistent level or variance shifts |
| Seasonal hybrid ESD | Robust decomposition plus statistical test | Outliers in seasonal metrics |
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.