Quick recap
The key takeaways of every lesson on one page. Read it in ten minutes to refresh the whole track; open a lesson when a point feels unclear.
01 Time series and decomposition
- A time series is a sequence in time order; its values are dependent, so never shuffle them or split them at random.
- Look at a time plot, a seasonal plot (one line per period) and a lag plot ( against ) before any modelling.
- Additive decomposition: ; multiplicative: , which becomes additive after a log transform.
- A seasonal pattern has a fixed calendar period ; a cycle has no fixed period and belongs to the trend-cycle.
- A trailing -MA lags a linear trend by steps; a symmetric MA has no lag; any MA over exactly one period removes a pattern with that period.
- For even the centred trend is the MA, with weights .
- Classical decomposition: trend by MA, seasonal indices as centred averages of the detrended values, remainder as the rest; it has no trend at the ends and a fixed seasonal pattern. STL is the robust default.
- Strength of seasonality , and in the same way with .
02 Stationarity and autocorrelation
- White noise has mean 0, variance and no autocorrelation; a random walk has and is not stationary.
- Weak stationarity: constant mean, finite variance, and depends only on the lag . Trends and seasonal patterns break it.
- A stationary AR(1) process () has variance and ACF ; is a unit root (a random walk).
- The sample ACF divides by , which keeps and the autocovariance matrix positive semidefinite; for white noise about 95 % of the values lie in , one lag at a time.
- The Ljung–Box statistic is approximately for white noise ( degrees of freedom for ARMA residuals).
- The PACF is the last coefficient of the best AR() predictor; ; for AR() it is 0 after lag .
- Differencing and seasonal differencing (after a log if needed) make many series stationary; signals over-differencing.
- ADF has the null "unit root", KPSS the null "stationary"; a large p-value proves nothing. Regressing one random walk on an independent one gives spurious significance.
03 Baselines and backtesting
- Benchmarks: mean ; naive ; seasonal naive with ; drift . Each is the best forecast for one simple model (white noise, random walk, seasonal random walk, random walk with drift).
- Under squared error the best forecast is the conditional mean; for a random walk this is the last value, and the -step error variance is (the fan).
- Good residuals are uncorrelated and have mean zero (essential); constant variance and normality are needed only for the usual intervals. Residuals are in-sample and do not measure accuracy.
- Evaluate with a rolling origin: many forecast origins, an expanding or sliding training window, a gap when data arrive late or features overlap the future, and errors reported per horizon .
- Random K-fold splits of a time series interpolate and see the future, so they are usually too optimistic; they are valid only for autoregressive models with uncorrelated errors on stationary data.
- MSE is minimised by the mean, MAE by the median, and MAPE by a value below the median ( for a log-normal); choose the metric from the decision.
- MASE divides the test MAE by the in-sample MAE of the one-step seasonal naive forecast, ; it is scale-free, and MASE < 1 means better than that in-sample benchmark.
- Avoid leakage: fit every preprocessing step inside each training window, never fill from the future, use only data and covariates available at each origin.
04 Exponential smoothing
- SES forecast: (flat), with ; equivalently a weighted average with weights plus , summing to 1.
- Small means long memory (average age ); is the naive forecast. Fit (and ) by minimising the SSE of one-step errors.
- Holt: , a straight line; the damped trend uses , which tends to .
- Holt-Winters adds seasonal states; the forecast uses with . Additive for swings of fixed size, multiplicative (or logs) for swings that grow with the level.
- Error-correction form: each state = its prediction + gain × one-step error, with gains , , .
- ETS (Error, Trend, Seasonal) adds an error model to the recursions: ETS(A,N,N) is , ; its point forecasts equal SES.
- The ETS model gives a likelihood (model choice by AICc) and prediction intervals; for ETS(A,N,N) the -step variance is .
- On the CO₂ backtest, additive and multiplicative Holt-Winters have MASE about 0.27, against 1.00 for the seasonal naive forecast; non-seasonal methods lose to the benchmark.
05 AR, MA and ARMA
- AR(): with ; a stationary AR() has mean .
- An AR() is stationary (and causal) when all roots of lie outside the unit circle, equivalently all eigenvalues of the companion matrix lie inside it; eigenvalues are the reciprocals of the roots.
- AR(2) is stationary inside the triangle , , ; below the parabola it has a quasi-cycle with period , .
- Yule–Walker: for , a Toeplitz system that gives the ACF from or estimates from the sample ACF.
- MA() is always stationary and its ACF cuts off after lag ; for MA(1), , so .
- and give the same ACF; choose the invertible MA (roots of outside the unit circle), which is an AR(), so its PACF decays.
- Identification: AR() has a PACF cut-off at , MA() an ACF cut-off at , ARMA neither; then compare candidates by AIC/AICc/BIC on the same data and check residuals with Ljung–Box.
- AR(2) fitted to the yearly sunspots gives and a quasi-period of 10.9 years.
06 ARIMA and SARIMA
- ARIMA(): ; the -times differenced series is a stationary, invertible ARMA.
- Random walk = ARIMA(0,1,0); with a constant it has drift; SES with parameter = ARIMA(0,1,1) with .
- Forecast recursion: write the model at time , replace future values by forecasts, future shocks by 0 and past shocks by residuals.
- Forecast error variance: ; bounded for a stationary model, grows like (width like ) for a random walk.
- The constant and fix the long-run forecast: mean (), constant or line (), line or quadratic ().
- SARIMA multiplies seasonal polynomials in ; the airline model has MA terms at lags 1, 12, 13 and only two MA coefficients.
- Box–Jenkins: transform, difference, identify, compare by AICc on the same differencing, check residuals (Ljung–Box), forecast, back-transform ( of a log forecast is the median).
- Regression with ARIMA errors needs the future covariates; Fourier terms model long seasonal periods.
07 State space and Kalman filter
- A linear Gaussian state-space model is , (hidden state) and , (observation). Local level, trend, seasonal and ARMA models are all special cases.
- The Kalman filter predicts , , then updates with the innovation , its covariance and the gain .
- One scalar update is Bayes' rule for two Gaussians: precisions add, and the new mean is the prediction plus times the innovation. when and when .
- Under the model assumptions the filter gives the exact posterior (Gaussian conditioning, by induction).
- For the local level model the gain converges to with , and the filter becomes simple exponential smoothing with .
- Forecasts repeat the predict step; missing observations skip the update, so the variance grows (by per step for the local level).
- The log-likelihood is (prediction-error decomposition); maximise it to estimate , and other parameters. Nile: , .
- The RTS smoother uses all data and has smaller variances; use it to describe the past, never at a forecast origin.
08 ML for forecasting
- Reduction to supervised learning: each row has features known at the origin (lags , rolling statistics, calendar, covariates) and the target ; the table has rows.
- Leakage is any feature that uses information after the forecast origin; compute window features after
shift(h), and fit encodings and scales on training data only. - Covariates are static, known in advance, or observed only; in the direct strategy a lag of the target or of an observed-only covariate is usable at horizon only if .
- Tree ensembles predict means of training targets and are constant beyond the largest split thresholds, so they cannot follow a trend; model differences, ratios or residuals from a trend instead.
- Recursive forecasting uses one model and feeds forecasts back (errors accumulate); direct forecasting uses one model per horizon; multi-output predicts all horizons at once.
- With one lag, : direct is never worse under misspecification, and equal for a true AR(1).
- A global model trained on many series shares patterns and has more rows than a local model; it needs per-series scaling computed from training data.
- Validate gradient boosting with a rolling origin and a time-based early-stopping block, never with a random split.
09 Deep learning for forecasting
- A neural forecaster maps a context of length to future values or to a distribution; each window is scaled with its own context statistics (mean scaling, RevIN), and the scaling is undone at the output. Scaling with future values is leakage.
- DeepAR is a global autoregressive RNN with a likelihood head: training with true inputs (teacher forcing) is maximum likelihood, and ancestral sampling gives exact samples of the joint forecast distribution.
- A stack of causal convolutions with kernel and dilations has receptive field and never uses future inputs; doubling dilations make grow exponentially with depth. A TCN block has two convolutions.
- DLinear, , has exactly the function class of a linear map on the window, and such linear models beat several long-horizon transformers on standard benchmarks: always include a linear baseline.
- PatchTST turns patches of values with stride into tokens, cutting attention cost by about , and shares one model across channels (channel independence).
- Time-series foundation models are pretrained on many series and used zero-shot (no training on the target data) or fine-tuned; they differ in tokens (quantised values, patches), heads (bins, points, distributions, quantiles, flow matching) and backbone.
- Chronos divides by the mean absolute value and quantises into about 4,000 bins on ; the rounding error is at most and values beyond are clipped.
- Evaluate deep and pretrained models like any forecaster: rolling-origin backtests on your own series, against seasonal naive, ETS and boosting, and watch for benchmark contamination.
10 Probabilistic forecasting
- A probabilistic forecast is a predictive distribution, a set of quantiles, an interval or a set of sample paths; only sample paths answer questions about sums or maxima over several horizons.
- The pinball loss with has expected value minimised at the -quantile, because its derivative is ; training any model with it gives quantile regression.
- The best stock level under linear costs is the quantile at the critical ratio .
- Calibration means that the PIT values are uniform (central intervals have their nominal coverage); a U-shaped PIT histogram means intervals that are too narrow, a hump means too wide.
- Calibration is necessary but not sufficient: maximise sharpness subject to calibration.
- The CRPS is a strictly proper score in the units of ; for a point forecast it is the absolute error.
- Split conformal uses the -th smallest calibration score as the half-width; with exchangeable data its coverage is at least (marginal, not conditional).
- Time series break exchangeability; adaptive conformal inference keeps the long-run miss rate within of for any sequence.
11 Anomaly detection
- Time-series anomalies come in four kinds: point anomalies, contextual anomalies (normal value, wrong time), collective anomalies (unusual shape) and change points (a lasting change of the distribution).
- The standard recipe is expected value (decomposition, one-step forecast or filter), residual, robust score and threshold; the expected value must include the season, or contextual anomalies stay hidden.
- The robust z-score is on the scale of an ordinary z-score for Gaussian data and is not pulled by the anomalies; the mean and standard deviation suffer from masking.
- Choose the threshold from a false-alarm budget: checks with per-check rate give false alarms, for example 14.4 per day for one check per minute at .
- The CUSUM with alarm at adds up evidence for a shift; makes it the maximised log-likelihood ratio for a shift of , and it detects small shifts much faster than a single-value rule at the same false-alarm rate.
- Detectors of changes are compared by the average run length: large (no change) and small (delay after a shift).
- The matrix profile gives each window the z-normalised distance to its nearest non-overlapping neighbour; its maximum, the discord, is a collective anomaly.
- Point-adjusted F1 lets random detectors score high; evaluate with event recall, alarm precision, delay and false alarms per day, against a random and a simple robust baseline.