Skip to content
elevatedevco

Cheat sheet · Time Series & RL

Time Series cheat sheet

The key ideas on one page — plus common pitfalls and interview tips. Skim it before an interview, or print it for revision.


Cheat sheet

A dense, interview-grade reference covering time series fundamentals (stationarity, ACF/PACF), classical models (ARIMA/SARIMA, ETS), ML and deep learning approaches (gradient boosting, N-BEATS/N-HiTS, TFT, foundation models), and rigorous validation and evaluation. Geared to 2026 practice where global ML models and pretrained foundation forecasters dominate large-scale forecasting.

Core Concepts & Stationarity

  • A time series has temporal ordering and observations are autocorrelated, so i.i.d. assumptions break down — never shuffle when creating train/test splits.
  • Decomposition: y_t = Trend + Seasonality + Residual (additive) or Trend x Seasonality x Residual (multiplicative; take logs to convert multiplicative to additive). STL is the robust, modern default and handles changing seasonality.
  • Strict stationarity: the full joint distribution is time-invariant. Weak (covariance) stationarity: constant mean, constant variance, and autocovariance depending only on lag — the practical requirement for ARMA.
  • Achieve stationarity via differencing (d), seasonal differencing (D), log/Box-Cox for variance stabilization, and detrending. Over-differencing inflates variance and introduces spurious MA structure.
  • Tests are complementary: ADF (H0 = unit root / non-stationary) and KPSS (H0 = stationary). Run both — ADF rejects AND KPSS fails to reject => stationary.
  • ACF measures correlation at lag k including indirect effects; PACF measures correlation at lag k after removing intermediate lags. Together they guide ARMA order selection.
  • Beware spurious regression: two independent trending (non-stationary) series can show high R^2. Difference first, or test for cointegration before regressing levels.

Classical Models: ARIMA / SARIMA / ETS

  • AR(p): y_t = c + sum_i phi_i * y_{t-i} + e_t. MA(q): y_t = c + e_t + sum_i theta_i * e_{t-i}. ARMA combines both on a stationary series.
  • ARIMA(p,d,q): ARMA applied after d-th differencing. SARIMA(p,d,q)(P,D,Q)_m adds seasonal AR/MA/differencing terms with period m.
  • Order selection heuristics: PACF cuts off at lag p for pure AR, ACF cuts off at lag q for pure MA; when both decay, compare candidates by AIC/BIC. auto_arima / AutoARIMA automates the search.
  • ETS (Exponential Smoothing) decomposes into Error/Trend/Seasonality; Holt-Winters handles trend + seasonality. Often beats ARIMA on seasonal business data and is a strong, fast baseline.
  • SARIMAX adds exogenous regressors (holidays, promotions, weather). Exogenous values must be known or separately forecastable at prediction time.
  • Diagnostics: residuals should be white noise — check the Ljung-Box test (H0 = no autocorrelation), residual ACF, and approximate normality.
  • Strengths: interpretable, well-calibrated prediction intervals, excellent on a single well-behaved series. Weakness: scales poorly to thousands of series and rich feature sets.

ML & Deep Learning Approaches

  • Reframe forecasting as supervised learning: build lag features (y_{t-1..t-k}), rolling stats (mean/std/min/max), calendar features (day-of-week, month, holiday), and Fourier terms for seasonality.
  • Gradient-boosted trees (LightGBM/XGBoost) on engineered features are the pragmatic state of the art for tabular/retail forecasting (M5 winner). Trees cannot extrapolate trend — detrend, difference, or add explicit trend features.
  • Global models: train ONE model across many related series (cross-learning) instead of one model per series — better data efficiency and generalization. This is the dominant industrial pattern.
  • Deep learning: DeepAR (probabilistic RNN), N-BEATS / N-HiTS (pure MLP, strong and fast), Temporal Fusion Transformer (interpretable; handles static, known-future, and observed covariates), PatchTST (patch-based transformer).
  • Foundation/pretrained forecasters (2024-2026): TimesFM, Chronos, Moirai, TimeGPT, Lag-Llama enable strong zero/few-shot forecasting and serve as competitive baselines with little tuning.
  • Direct vs recursive multi-step: recursive feeds predictions back (errors accumulate); direct trains one model per horizon (no accumulation, more models). Seq2seq/multi-output models predict the whole horizon at once.
  • Prefer probabilistic forecasts (quantiles / intervals) via quantile (pinball) loss or distributional heads — point forecasts alone are rarely enough for decisions.

Validation & Evaluation

  • Never random-split. Use temporal holdout and rolling/expanding-window cross-validation (walk-forward / backtesting) that mimics real deployment.
  • Expanding window grows the train set each fold; sliding window keeps it fixed-size (better under regime shift / stale history).
  • Add a gap/embargo between train and test (>= the forecast horizon and >= the longest feature window) to prevent leakage from overlapping windows.
  • Scale-dependent errors: MAE, RMSE (penalizes large errors). Percentage: MAPE (undefined at zeros, asymmetric — under-penalizes over-forecasts), sMAPE. Scale-free: MASE (vs naive baseline; >1 means worse than naive).
  • Probabilistic metrics: pinball/quantile loss, CRPS, and interval coverage (does the nominal 90% PI actually contain ~90% of actuals?).
  • Always benchmark against naive baselines: naive (last value), seasonal naive (value m periods ago), and drift. Beating seasonal naive is the real bar.
  • Watch concept/seasonal drift: monitor error over time in production and retrain on a schedule or via a trigger.

Feature Engineering & Leakage Control

  • Golden rule: every feature must be computable using ONLY information available at prediction time. Lag/rolling windows must be strictly past-shifted.
  • Encode seasonality with Fourier terms (sin/cos pairs) for smooth periodicity plus categorical calendar features; sum terms across multiple seasonalities (daily + weekly + yearly).
  • Holidays, events, promotions, and price are high-value exogenous regressors — but their future values must be known or forecastable to use them at inference.
  • Static (per-series) features — store size, region, product category — let global models segment behavior; feed them as embeddings in deep models.
  • Fit transforms (scaling, Box-Cox, target encoding) on TRAIN folds only, then apply to validation/test. Per-series normalization helps when scales differ wildly.
  • Handle missing data deliberately: forward-fill vs interpolation vs masking changes results; irregular timestamps may need resampling to a fixed frequency.
  • Treat outliers/anomalies (e.g., COVID, stockouts) with robust decomposition or indicator flags to avoid distorting trend/seasonality estimates.

Specialized Topics

  • Volatility modeling: ARCH/GARCH capture time-varying variance (volatility clustering) — standard in finance; the mean can be flat while variance is forecastable.
  • Cointegration & VAR/VECM: multivariate systems whose series move together long-run; Granger causality tests whether one series helps predict another (predictive, not true causality).
  • Intermittent demand (many zeros): Croston's method and variants (SBA, TSB) or Tweedie-loss GBMs; MAPE/sMAPE are meaningless here — use MASE or scaled errors.
  • Hierarchical/grouped forecasting: forecasts must be coherent across aggregation levels (store -> region -> total). Use reconciliation (bottom-up, top-down, MinT optimal).
  • Change-point / anomaly detection: detect regime shifts in mean/variance/trend via Bayesian change-point, CUSUM, or residual-based detectors.
  • Long-horizon forecasting: PatchTST, N-HiTS, and foundation models target very long horizons where recursive methods degrade.
  • Causal impact / intervention analysis: estimate an event's effect against a counterfactual (Bayesian structural time series / synthetic control).