Skip to content
ml-recall

Topic notes

Time Series

Data indexed in time order - trend, seasonality and stationarity, differencing, AR/MA/ARIMA with ACF and PACF, exponential smoothing, ML forecasting features, honest validation and state-space models.

4-min read AI-checked

Practise 59 questions Take a test

Key ideas

Formulas

Worked example

yt=3+0.5 yt−1+εty_t = 3 + 0.5\,y_{t-1} + \varepsilon_t with last value yT=10y_T = 10.

In code

import numpy as np
import pandas as pd
from sklearn.model_selection import TimeSeriesSplit

y = pd.Series(np.arange(1.0, 11.0))                     # toy series 1, 2, ..., 10
X = pd.DataFrame({"lag1": y.shift(1),                   # value at t-1
                  "mean3": y.shift(1).rolling(3).mean()})  # mean of t-3..t-1, no leakage
print(X.iloc[3].tolist())                               # [3.0, 2.0]  features for y = 4
for tr, te in TimeSeriesSplit(n_splits=3).split(X):
    print(len(tr), te)                                  # 4 [4 5] / 6 [6 7] / 8 [8 9]

Common pitfalls

References

  1. Hyndman & Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), Ch. 2 Time series graphics — Sec. 2.3 Time series patterns; Sec. 2.9 White noise
  2. Hyndman & Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), Ch. 9 ARIMA models — Sec. 9.1 Stationarity and differencing; 9.3 Autoregressive models; 9.4 Moving average models; 9.5 Non-seasonal ARIMA models (ACF and PACF plots); 9.7 ARIMA modelling in fable (Understanding constants in R; Plotting the characteristic roots); 9.8 Forecasting; 9.9 Seasonal ARIMA models
  3. Wikipedia: Stationary process — Strict-sense stationarity; Weak or wide-sense stationarity; Relationships between types of stationarity; Techniques to stationarize a non-stationary process
  4. Hyndman & Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), Ch. 8 Exponential smoothing — Sec. 8.1 Simple exponential smoothing (Weighted average form; Flat forecasts)
  5. Hyndman & Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), Ch. 7 Time series regression models — Sec. 7.2 Least squares estimation (Goodness-of-fit); Sec. 7.4 Some useful predictors; Sec. 7.7 Nonlinear regression
  6. Wikipedia: Kalman filter — Underlying dynamic system model; Details (Predict, Update)