Time Series#
Time-series methods apply to anything indexed by time: telemetry, market data, sensor streams, log counts, request rates. The operator’s question is usually one of three: what is the trend, is this point unusual, what will happen next.
Decomposition#
Every time series y(t) splits into:
Trend, the long-run direction.
Seasonality, periodic component (daily, weekly, yearly).
Cycle, longer non-seasonal periodicity (business cycle).
Noise / residual, what’s left.
The standard decompositions:
Method |
Detail |
|---|---|
Additive vs multiplicative |
|
STL (Seasonal-Trend by Loess) |
The default robust decomposition. Handles missing data and outliers. |
X-13ARIMA-SEATS |
The reference for economic / official statistics. |
Smoothing#
Method |
Detail |
|---|---|
Moving average (SMA) |
Mean over a sliding window. Lags by half the window. |
Exponentially weighted moving average (EWMA) |
Recent weights heavier; one parameter (alpha). |
Holt-Winters / triple exponential smoothing |
EWMA plus trend plus seasonality. The classic operator default for short forecasts. |
LOWESS / LOESS |
Local regression. Non-parametric, smooth, no period assumption. |
Savitzky-Golay |
Polynomial fit over a sliding window. Preserves peak shapes. |
Kalman filter |
State-space smoother; see Probabilistic. |
Stationarity#
A series is stationary if its statistical properties (mean, variance, autocorrelation) don’t change with time. Many models (ARIMA) assume stationarity; the operator checks first.
ADF (Augmented Dickey-Fuller) test, null hypothesis is non-stationary. Low p-value => reject => stationary.
KPSS test, opposite null. Pair with ADF.
Differencing,
y'(t) = y(t) - y(t-1). Removes a trend.Log transform, removes multiplicative growth.
Forecasting#
Raw signal, the smoothed trend the operator fits on history, and the forecast horizon extending past the last observation.
xychart-beta
title "Trend + seasonality + forecast (illustrative)"
x-axis [t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12]
y-axis "value" 0 --> 120
line [42, 58, 51, 68, 74, 65, 82, 88, 80, 95, 102, 94]
line [45, 52, 58, 64, 70, 76, 82, 88, 94, 100, 106, 112]
line [0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 108, 116]
Method |
Use |
|---|---|
Naive / seasonal naive |
Last value or last seasonal value. The baseline every model must beat. |
Holt-Winters |
Short horizon, strong seasonality, no exogenous inputs. Cheap. |
ARIMA / SARIMA |
Autoregressive Integrated Moving Average. The classical model. SARIMA adds seasonality. |
VAR |
Vector AR. Multivariate time series with cross-dependencies. |
State-space (Kalman, BSTS) |
Latent-state models. Handles missing data and structural breaks. |
Prophet |
Facebook’s piecewise-linear trend + Fourier seasonality + holidays. Easy to use, opinionated. |
Exponential smoothing state-space (ETS) |
Modern Holt-Winters with information criteria for model selection. |
Gradient-boosted trees (LightGBM, XGBoost) |
Tabular forecasting with lag features. Often beats classical methods on rich feature sets. |
Deep learning (N-BEATS, TFT, DeepAR, transformers) |
Long-range forecasting at scale, when training data is abundant. |
ARIMA in operator practice#
ARIMA(p, d, q): p is autoregressive order, d is the
number of differences to make the series stationary, q is the
moving-average order. Read ACF and PACF plots to pick p and
q; or let auto.arima / pmdarima.auto_arima search.
import pmdarima as pm
model = pm.auto_arima(y, seasonal=True, m=24) # m=24 for hourly daily seasonality
fcst, ci = model.predict(n_periods=72, return_conf_int=True)
Anomaly in time series#
Two flavours:
Point anomalies, one observation deviates strongly. Detect with z-score on the residuals after smoothing or decomposition; with isolation forest on lag-windowed features; with prediction-residual thresholds.
Change points, the data-generating process itself changes. Detect with CUSUM, Bayesian online change-point detection, PELT (
ruptureslibrary), or windowed two-sample tests.
For deep treatment see Anomaly Detection.
Implementations#
Tool |
Detail |
|---|---|
statsmodels |
Python’s reference. ARIMA, SARIMAX, VAR, ETS, STL. |
pmdarima |
Auto-ARIMA in Python. |
prophet |
Facebook’s package. Easy default for series with strong seasonality. |
tslearn / sktime / Darts |
ML-shaped APIs over time-series problems. |
Pandas |
|
Pitfalls#
Leakage in feature engineering. Future information must not enter past features.
Backtesting with proper time-series cross-validation; random k-fold splits are wrong.
Time-zone confusion. Always store UTC in storage; convert at the display boundary.
Holiday and calendar effects dominate many business series; build them in explicitly.
References#
Statistics for the substrate.
Anomaly Detection for outlier and change-point detection.
Probabilistic for state-space models.