Time Series#
Observations indexed in time order, where sequence and dependence carry information.
Important
✨ AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.
What it is#
A time series is a sequence of observations recorded in time order, usually at equal spacing:
where \(Y_t\) is the value at time \(t\). The defining feature is that order matters — rows are not exchangeable the way they are in ordinary tabular data, because each value is related to those around it. Everyday examples include daily stock prices, monthly unemployment, hourly temperature, 15-minute electricity usage and a patient’s heart rate over time.
The four components#
A series is often decomposed into structure plus randomness:
Trend — long-run drift up or down (rising house prices).
Seasonality — a repeating pattern of fixed period (sales peaking every December).
Cyclic — wave-like swings of no fixed length (business cycles).
Noise — the residual that trend and seasonality do not explain.
Additively, \(Y_t = \text{Trend}_t + \text{Seasonality}_t + \text{Noise}_t\) (a multiplicative form fits when the seasonal swing grows with the level).
Types#
Univariate vs multivariate — one series, or several measured together (sales + temperature + promo spend).
Stationary vs non-stationary — a stationary series has constant mean and variance with no trend or seasonality. Most real data is non-stationary; differencing or detrending is used to make it stationary, and a test such as the Augmented Dickey-Fuller (ADF) test checks it.
Modelling approaches#
Classical statistics — AR, MA, ARMA, ARIMA (adds differencing for trend), SARIMA (adds seasonality) and exponential smoothing (Holt-Winters).
General ML on lag features — reshape the series into a supervised table of lagged values and fit Random Forest or gradient boosting (XGBoost).
Deep learning — RNN / LSTM / GRU, Temporal Convolutional Networks, and Transformer variants (Informer, TimesNet) for long or multivariate series.
Forecasting vs analysis#
Two distinct goals: forecasting predicts future values (tomorrow’s temperature), while analysis explains structure — detecting trend, decomposing seasonality, or flagging anomalies in a sensor stream.
Evaluation metrics#
Forecasts are scored with MAE, MSE, RMSE, and percentage errors MAPE, sMAPE and WAPE. Choose carefully: MAPE explodes when actual values are near zero and penalises over- and under-prediction asymmetrically; sMAPE and WAPE are more robust for intermittent or zero-heavy data.
Pitfalls and edge cases#
Leakage from random splits — the single biggest mistake. A shuffled train/test split lets the model peek at the future. Always split by time (train on the past, test on the later portion) with a temporal / rolling-window scheme.
Look-ahead features — every feature must be computable from information available at prediction time; rolling statistics must not include the current or future point.
Autocorrelation — residuals are usually correlated in time, which breaks the i.i.d. assumption behind ordinary error bars.
Non-stationarity and regime change — relationships drift, so a model fit on old data can silently degrade.
Seasonality mismatch — the model must capture the right period (weekly and yearly cycles can coexist).
Worked example — decompose, then split by time#
import pandas as pd
from statsmodels.tsa.seasonal import seasonal_decompose
# y: a pandas Series on a daily DatetimeIndex with weekly seasonality
parts = seasonal_decompose(y, model="additive", period=7)
trend, seasonal, resid = parts.trend, parts.seasonal, parts.resid
# temporal hold-out: NEVER shuffle a time series
split = int(len(y) * 0.8)
train, test = y.iloc[:split], y.iloc[split:]
Theme: Signal Processing & Time Series · All terminology
Hint
Mind map — connected ideas
Time Series Forecasting · ARIMA (AutoRegressive Integrated Moving Average) · Seasonality · Temporal autocorrelation (Serial Correlation) · Time-based splits (a.k.a. Temporal Cross-Validation, Rolling Window Validation) · Signal Processing
Hint
More in Signal Processing & Time Series
ARIMA (AutoRegressive Integrated Moving Average) · Bayesian Time Series · Forecast Error · Forecasting Benchmarks · Forecasting Competitions · Log-Space · Low-pass Filtering · LSTM — Long Short-Term Memory Networks · M-Competitions (Makridakis Competitions) · Naïve Baseline Forecast · Prophet — Time Series Forecasting by Facebook (Meta) · Seasonal Lag · Seasonality · Signal Processing
See also
Source article Adapted (context, re-expressed) in our own words from: Time Series (insightful-data-lab.com).