liveBook · Manning

Forecast error

As explained in Outlier Detection in Python

A forecast error is the difference between an observed value and the value predicted for the same time point.

Forecast error is the difference between an observed value and the value predicted for the same time point. In outlier detection, unusually large errors indicate observations that differ substantially from expectation. section 17.2.6

A forecasting model can incorporate recent values, ruptures, trends, and cycles. Interpret an error relative to normal errors, for example by comparing it with the median error and median absolute deviation. section 17.2.6

A practical workflow is:

  • Forecast each value from prior observations using a time-series or regression model. section 17.2.6
  • Calculate the difference between each forecast and its actual value. section 17.2.6
  • Compare errors with their usual scale rather than treating every nonzero error as anomalous. section 17.2.6

A large deviation

If the forecast is 50 and the observed value is 240, the error is 190. When typical errors are around 10 or 20, this observation is a candidate outlier. section 17.2.6

Listing 17.7 Forecasting values using Darts with ARIMA
from darts import TimeSeries
from darts.models import ARIMA
 
df['timestamp'] = df.index                                         #1
series = TimeSeries.from_dataframe(df, "timestamp", "Values")
 
model = ARIMA(p=7, d=2, q=2)                                       #2
model.fit(series[:-60])
pred = model.predict(60)                                           #3
 
pred.plot(label="forecast", low_quantile=0.05, high_quantile=0.95) #4
plt.legend()
plt.show()

Fits ARIMA on earlier values and predicts a held-out interval, providing forecasts from which errors can be calculated. section 17.2.6

How Outlier Detection in Python covers it

How deep it goes
Explains calculation, robust comparison, forecasting choices, and limitations from model accuracy and parameter tuning.
Examples
Uses synthetic weekly-pattern data, a 50-to-240 deviation, a deliberately modified value, and held-out forecasts.
What it assumes
Assumes time-ordered observations and prior values, while introducing forecasting-based anomaly scoring through concrete examples.
What you can do after
Diagnose candidate outliers by comparing forecast errors with the normal error distribution.
How it connects
Connects time-series outlier detection with ARIMA, Exponential Smoothing, Random Forest regression, and MAPE.

Also explained in

Compare how 2 books explain forecast error →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.