liveBook · Manning

Anomaly detection

As explained in Time Series Forecasting Using Foundation Models

Anomaly detection is the task of identifying observations or patterns that substantially deviate from expected behavior.

Anomaly detection identifies observations or patterns that substantially deviate from expected behavior. In time series, a practical approach forecasts historical values and flags points outside a prediction interval. section 3.8

Forecast-based detection repurposes probabilistic forecasting rather than using a separate anomaly-specific technique. Rolling or historical forecasts produce lower and upper bounds; an actual value outside those bounds receives an anomaly label. section 3.8 section 6.4

A typical implementation proceeds as follows:

  • Prepare a time series with timestamps, target values, and—when available—actual anomaly labels for evaluation. section 3.8.1
  • Generate historical or rolling forecasts over the period being tested, using windows and a forecast horizon that cover the desired dates. section 5.8 section 6.4
  • Compute prediction intervals and flag each actual value below the lower bound or above the upper bound. section 9.5 section 9.5.1
  • Measure precision, recall, and F1 score; inspect the trade-off because narrower intervals increase recall but reduce precision. section 3.10 section 6.4

Daily taxi rides

On daily New York City taxi-customer counts from July 2014 through January 2015, TimeGPT used historical forecasts and a 99% prediction interval. It labeled eight points anomalous while four were actual anomalies, illustrating false positives and missed early points. Chronos found all labeled anomalies but achieved only 21% precision; Moirai also found all actual anomalies and achieved the best reported F1 score in that experiment, 0.53. These single-dataset results are comparisons, not comprehensive benchmarks. section 3.8.1 section 5.8 section 6.4

Figure 3.18 Plotting the anomalies detected by TimeGPT. The dotted line shows the historical forecasts. The shaded area represents the 99% prediction interval. If a point falls outside the interval, it is labeled an anomaly. Diamonds indicate predicted anomalies, and dots represent the actual anomalies not detected by TimeGPT. If a detected anomaly and an actual anomaly coincide, meaning that the model identified the anomaly correctly, only a diamond is shown.
A graph with green and blue lines

AI-generated content may be incorrect.

Inspect the forecast line, shaded 99% prediction interval, predicted anomaly diamonds, and labeled anomaly dots. section 3.8.1

How Time Series Forecasting Using Foundation Models covers it

How deep it goes
Works through rolling forecasts, interval thresholds, implementation functions, plots, and precision-recall evaluation, but stops short of comprehensive benchmarking.
Examples
Uses daily New York City taxi rides to compare TimeGPT, Chronos, Moirai, Time-LLM, Flan-T5, and Llama-3.2.
What it assumes
Assumes basic Python and time-series handling while demonstrating interval-based labeling, rolling forecasts, and classification metrics.
What you can do after
Apply it via forecasting APIs or Python workflows, then diagnose detections with plots and precision, recall, and F1 score.
How it connects
Connects anomaly detection with time-series forecasting, prediction intervals, cross-validation, conformal prediction, precision, recall, and F1 score.

Also explained in

Compare how 7 books explain anomaly detection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Time Series Forecasting Using Foundation Models. The section links point to the parts of the book it draws on.