Type at least 2 letters. Enter opens the first result, Esc closes.

    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 y1,…,yny_1, \dots, y_n 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 (yty_t against yt−ky_{t-k}) before any modelling.
    • Additive decomposition: yt=Tt+St+Rty_t = T_t + S_t + R_t; multiplicative: yt=Tt⋅St⋅Rty_t = T_t \cdot S_t \cdot R_t, which becomes additive after a log transform.
    • A seasonal pattern has a fixed calendar period mm; a cycle has no fixed period and belongs to the trend-cycle.
    • A trailing kk-MA lags a linear trend by (k−1)/2(k-1)/2 steps; a symmetric MA has no lag; any MA over exactly one period removes a pattern with that period.
    • For even mm the centred trend is the 2×m2 \times m MA, with weights 12m,1m,…,1m,12m\tfrac{1}{2m}, \tfrac1m, \dots, \tfrac1m, \tfrac{1}{2m}.
    • 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 FS=max⁡(0,1−Var⁡(Rt)/Var⁡(St+Rt))F_S = \max(0, 1 - \operatorname{Var}(R_t)/\operatorname{Var}(S_t + R_t)), and FTF_T in the same way with TtT_t.

    02 Stationarity and autocorrelation

    • White noise has mean 0, variance σ2\sigma^2 and no autocorrelation; a random walk yt=yt−1+εty_t = y_{t-1} + \varepsilon_t has Var⁡(yt)=tσ2\operatorname{Var}(y_t) = t\sigma^2 and is not stationary.
    • Weak stationarity: constant mean, finite variance, and Cov⁡(yt,yt+k)=γ(k)\operatorname{Cov}(y_t, y_{t+k}) = \gamma(k) depends only on the lag kk. Trends and seasonal patterns break it.
    • A stationary AR(1) process yt=ϕyt−1+εty_t = \phi y_{t-1} + \varepsilon_t (∣ϕ∣<1|\phi| < 1) has variance σ2/(1−ϕ2)\sigma^2/(1-\phi^2) and ACF ρ(k)=ϕk\rho(k) = \phi^k; ϕ=1\phi = 1 is a unit root (a random walk).
    • The sample ACF divides by nn, which keeps ∣ρ^(k)∣≤1|\hat\rho(k)| \le 1 and the autocovariance matrix positive semidefinite; for white noise about 95 % of the values lie in ±1.96/n\pm 1.96/\sqrt n, one lag at a time.
    • The Ljung–Box statistic Q=n(n+2)∑k=1ℓρ^(k)2/(n−k)Q = n(n+2)\sum_{k=1}^{\ell} \hat\rho(k)^2/(n-k) is approximately χℓ2\chi^2_\ell for white noise (ℓ−p−q\ell - p - q degrees of freedom for ARMA residuals).
    • The PACF ϕkk\phi_{kk} is the last coefficient of the best AR(kk) predictor; ϕ22=(ρ(2)−ρ(1)2)/(1−ρ(1)2)\phi_{22} = (\rho(2) - \rho(1)^2)/(1 - \rho(1)^2); for AR(pp) it is 0 after lag pp.
    • Differencing ∇=1−B\nabla = 1 - B and seasonal differencing ∇m=1−Bm\nabla_m = 1 - B^m (after a log if needed) make many series stationary; ρ^(1)≈−0.5\hat\rho(1) \approx -0.5 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 yˉ\bar y; naive yny_n; seasonal naive yn+h−m(k+1)y_{n+h-m(k+1)} with k=⌊(h−1)/m⌋k = \lfloor (h-1)/m\rfloor; drift yn+h (yn−y1)/(n−1)y_n + h\,(y_n - y_1)/(n-1). 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 hh-step error variance is hσ2h\sigma^2 (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 hh.
    • 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 (eμ−σ2e^{\mu - \sigma^2} 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, 1n−m∑t=m+1n∣yt−yt−m∣\frac{1}{n-m}\sum_{t=m+1}^{n}\lvert y_t - y_{t-m}\rvert; 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: y^t+h∣t=ℓt\hat y_{t+h\mid t} = \ell_t (flat), with ℓt=αyt+(1−α)ℓt−1=ℓt−1+αet\ell_t = \alpha y_t + (1-\alpha)\ell_{t-1} = \ell_{t-1} + \alpha e_t; equivalently a weighted average with weights α(1−α)j\alpha(1-\alpha)^j plus (1−α)tℓ0(1-\alpha)^t\ell_0, summing to 1.
    • Small α\alpha means long memory (average age (1−α)/α(1-\alpha)/\alpha); α=1\alpha = 1 is the naive forecast. Fit α\alpha (and ℓ0\ell_0) by minimising the SSE of one-step errors.
    • Holt: y^t+h∣t=ℓt+hbt\hat y_{t+h\mid t} = \ell_t + h b_t, a straight line; the damped trend uses ℓt+(ϕ+⋯+ϕh)bt\ell_t + (\phi + \dots + \phi^h) b_t, which tends to ℓt+ϕ1−ϕbt\ell_t + \frac{\phi}{1-\phi} b_t.
    • Holt-Winters adds mm seasonal states; the forecast uses st+h−m(k+1)s_{t+h-m(k+1)} with k=⌊(h−1)/m⌋k = \lfloor (h-1)/m \rfloor. 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 α\alpha, αβ∗\alpha\beta^*, γ\gamma.
    • ETS (Error, Trend, Seasonal) adds an error model to the recursions: ETS(A,N,N) is yt=ℓt−1+εty_t = \ell_{t-1} + \varepsilon_t, ℓt=ℓt−1+αεt\ell_t = \ell_{t-1} + \alpha\varepsilon_t; its point forecasts equal SES.
    • The ETS model gives a likelihood (model choice by AICc) and prediction intervals; for ETS(A,N,N) the hh-step variance is σ2[1+α2(h−1)]\sigma^2[1 + \alpha^2(h-1)].
    • 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(pp): ϕ(B)yt=c+εt\phi(B)y_t = c + \varepsilon_t with ϕ(z)=1−ϕ1z−⋯−ϕpzp\phi(z) = 1 - \phi_1 z - \dots - \phi_p z^p; a stationary AR(pp) has mean μ=c/(1−ϕ1−⋯−ϕp)\mu = c/(1 - \phi_1 - \dots - \phi_p).
    • An AR(pp) is stationary (and causal) when all roots of ϕ(z)\phi(z) 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 ϕ1+ϕ2<1\phi_1 + \phi_2 < 1, ϕ2−ϕ1<1\phi_2 - \phi_1 < 1, ∣ϕ2∣<1|\phi_2| < 1; below the parabola ϕ12+4ϕ2<0\phi_1^2 + 4\phi_2 < 0 it has a quasi-cycle with period 2π/ω2\pi/\omega, cos⁡ω=ϕ1/(2−ϕ2)\cos\omega = \phi_1/(2\sqrt{-\phi_2}).
    • Yule–Walker: ρ(k)=∑i=1pϕiρ(k−i)\rho(k) = \sum_{i=1}^p\phi_i\rho(k-i) for k≥1k \ge 1, a Toeplitz system that gives the ACF from ϕ\phi or estimates ϕ\phi from the sample ACF.
    • MA(qq) is always stationary and its ACF cuts off after lag qq; for MA(1), ρ(1)=θ/(1+θ2)\rho(1) = \theta/(1 + \theta^2), so ∣ρ(1)∣≤0.5|\rho(1)| \le 0.5.
    • θ\theta and 1/θ1/\theta give the same ACF; choose the invertible MA (roots of θ(z)\theta(z) outside the unit circle), which is an AR(∞\infty), so its PACF decays.
    • Identification: AR(pp) has a PACF cut-off at pp, MA(qq) an ACF cut-off at qq, 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 ϕ^=(1.392,−0.690)\hat\phi = (1.392, -0.690) and a quasi-period of 10.9 years.

    06 ARIMA and SARIMA

    • ARIMA(p,d,qp,d,q): ϕ(B)(1−B)dyt=c+θ(B)εt\phi(B)(1 - B)^d y_t = c + \theta(B)\varepsilon_t; the dd-times differenced series is a stationary, invertible ARMA.
    • Random walk = ARIMA(0,1,0); with a constant it has drift; SES with parameter α\alpha = ARIMA(0,1,1) with θ=α−1\theta = \alpha - 1.
    • Forecast recursion: write the model at time n+hn + h, replace future values by forecasts, future shocks by 0 and past shocks by residuals.
    • Forecast error variance: Var⁡(en+h)=σ2∑j=0h−1ψj2\operatorname{Var}(e_{n+h}) = \sigma^2\sum_{j=0}^{h-1}\psi_j^2; bounded for a stationary model, grows like hh (width like h\sqrt h) for a random walk.
    • The constant and dd fix the long-run forecast: mean (d=0d = 0), constant or line (d=1d = 1), line or quadratic (d=2d = 2).
    • SARIMA (p,d,q)(P,D,Q)m(p,d,q)(P,D,Q)_m multiplies seasonal polynomials in BmB^m; the airline model (0,1,1)(0,1,1)12(0,1,1)(0,1,1)_{12} 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 (exp⁡\exp 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 xt=Fxt−1+wtx_t = Fx_{t-1} + w_t, wt∼N(0,Q)w_t \sim \mathcal N(0, Q) (hidden state) and yt=Hxt+vty_t = Hx_t + v_t, vt∼N(0,R)v_t \sim \mathcal N(0, R) (observation). Local level, trend, seasonal and ARMA models are all special cases.
    • The Kalman filter predicts x^t∣t−1=Fx^t−1∣t−1\hat x_{t\mid t-1} = F\hat x_{t-1\mid t-1}, Pt∣t−1=FPt−1∣t−1F⊤+QP_{t\mid t-1} = FP_{t-1\mid t-1}F^\top + Q, then updates with the innovation νt=yt−Hx^t∣t−1\nu_t = y_t - H\hat x_{t\mid t-1}, its covariance St=HPt∣t−1H⊤+RS_t = HP_{t\mid t-1}H^\top + R and the gain Kt=Pt∣t−1H⊤St−1K_t = P_{t\mid t-1}H^\top S_t^{-1}.
    • One scalar update is Bayes' rule for two Gaussians: precisions add, and the new mean is the prediction plus K=P/(P+R)K = P/(P + R) times the innovation. K→0K \to 0 when R→∞R \to \infty and K→1K \to 1 when R→0R \to 0.
    • Under the model assumptions the filter gives the exact posterior xt∣y1:t∼N(x^t∣t,Pt∣t)x_t \mid y_{1:t} \sim \mathcal N(\hat x_{t\mid t}, P_{t\mid t}) (Gaussian conditioning, by induction).
    • For the local level model the gain converges to K∞=12(q2+4q−q)K_\infty = \tfrac12(\sqrt{q^2 + 4q} - q) with q=Q/Rq = Q/R, and the filter becomes simple exponential smoothing with α=K∞\alpha = K_\infty.
    • Forecasts repeat the predict step; missing observations skip the update, so the variance grows (by QQ per step for the local level).
    • The log-likelihood is −12∑t(log⁡det⁡(2πSt)+νt⊤St−1νt)-\tfrac12\sum_t(\log\det(2\pi S_t) + \nu_t^\top S_t^{-1}\nu_t) (prediction-error decomposition); maximise it to estimate QQ, RR and other parameters. Nile: R^≈15 099\hat R \approx 15\,099, Q^≈1 469\hat Q \approx 1\,469.
    • 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 ys−h,…,ys−h−L+1y_{s-h}, \dots, y_{s-h-L+1}, rolling statistics, calendar, covariates) and the target ysy_s; the table has n−L−h+1n - L - h + 1 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 kk of the target or of an observed-only covariate is usable at horizon hh only if k≥hk \ge h.
    • 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, MSErec(h)−MSEdir(h)=γ(0)(ρ(1)h−ρ(h))2≥0\mathrm{MSE}_{\text{rec}}(h) - \mathrm{MSE}_{\text{dir}}(h) = \gamma(0)(\rho(1)^h - \rho(h))^2 \ge 0: 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 LL to HH 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 kk and dilations did_i has receptive field r=1+(k−1)∑idir = 1 + (k-1)\sum_i d_i and never uses future inputs; doubling dilations make rr grow exponentially with depth. A TCN block has two convolutions.
    • DLinear, y^=Ws(x−Ax)+WtAx+b\hat y = W_s(x - Ax) + W_tAx + b, 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 PP values with stride SS into N=⌊(L−P)/S⌋+2N = \lfloor (L-P)/S \rfloor + 2 tokens, cutting attention cost by about S2S^2, 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 ss and quantises into about 4,000 bins on [−15,15][-15, 15]; the rounding error is at most 15s/(B−1)15s/(B-1) and values beyond ±15s\pm 15s 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 ρτ(u)=max⁡{τu,(τ−1)u}\rho_\tau(u) = \max\{\tau u, (\tau - 1)u\} with u=y−qu = y - q has expected value minimised at the τ\tau-quantile, because its derivative is F(q)−τF(q) - \tau; training any model with it gives quantile regression.
    • The best stock level under linear costs is the quantile at the critical ratio τ=cu/(cu+co)\tau = c_u/(c_u + c_o).
    • Calibration means that the PIT values ut=Ft(yt)u_t = F_t(y_t) 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 ∫(F(x)−1{x≥y})2 dx=E∣X−y∣−12E∣X−X′∣=2∫01ρτ(y−F−1(τ)) dτ\int (F(x) - \mathbf 1\{x \ge y\})^2\,dx = \mathbb E|X - y| - \frac12\mathbb E|X - X'| = 2\int_0^1 \rho_\tau(y - F^{-1}(\tau))\,d\tau is a strictly proper score in the units of yy; for a point forecast it is the absolute error.
    • Split conformal uses the ⌈(n+1)(1−α)⌉\lceil (n + 1)(1 - \alpha)\rceil-th smallest calibration score as the half-width; with exchangeable data its coverage is at least 1−α1 - \alpha (marginal, not conditional).
    • Time series break exchangeability; adaptive conformal inference αt+1=αt+γ(α−errt)\alpha_{t+1} = \alpha_t + \gamma(\alpha - \mathrm{err}_t) keeps the long-run miss rate within (max⁡(α1,1−α1)+γ)/(γT)(\max(\alpha_1, 1 - \alpha_1) + \gamma)/(\gamma T) of α\alpha 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 (rt−med⁡r)/(1.4826⋅MAD)(r_t - \operatorname{med} r)/(1.4826\cdot\mathrm{MAD}) 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: NN checks with per-check rate pp give NpNp false alarms, for example 14.4 per day for one check per minute at p=0.01p = 0.01.
    • The CUSUM Ct=max⁡(0,Ct−1+zt−k)C_t = \max(0, C_{t-1} + z_t - k) with alarm at Ct>hcC_t > h_c adds up evidence for a shift; k=δ/2k = \delta/2 makes it the maximised log-likelihood ratio for a shift of δ\delta, 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 ARL0\mathrm{ARL}_0 (no change) and small ARL1\mathrm{ARL}_1 (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.