Time Series Forecasting

Trend, seasonality, lag features and proper backtesting, from classical models to gradient boosting and deep forecasters.

Intermediate · about 10 hours · difficulty 3/5

Learn first: Gradient Boosting with XGBoost and LightGBM, Cross-Validation

Forecasting demand, traffic, prices or sensor readings is one of the most common business uses of ML, and one of the easiest to get wrong because time breaks the usual assumptions.

Understand the series first

  • Plot it. Look for trend, seasonality (daily, weekly, yearly), holidays, outliers and structural breaks.
  • Decomposition separates trend, seasonal and residual parts.
  • Stationarity and autocorrelation plots (ACF, PACF) guide classical model choices.

Model options

  • Baselines: last value, seasonal naive (same day last week) and moving averages. Always report them.
  • Classical: exponential smoothing (ETS) and ARIMA/SARIMA, strong on single series with clear patterns.
  • ML on features: build lag features, rolling statistics and calendar features, then use gradient boosting. This wins many competitions and works across many related series.
  • Deep and foundation models: N-BEATS, temporal fusion transformers and pretrained forecasting models for large collections of series.

Evaluation without cheating

Never shuffle. Use rolling-origin backtesting (train up to time t, forecast the next horizon, move forward, repeat). Compute rolling features using only past data. Choose metrics that match the business: MAE, RMSE, MAPE (breaks near zero) or MASE, and produce prediction intervals, not just point forecasts.

Good enough to move on when you can beat a seasonal naive baseline in a proper backtest and explain which features could have leaked future information.

Key concepts

  • Trend and seasonality decomposition
  • Naive and seasonal baselines
  • ARIMA and exponential smoothing
  • Lag and rolling features
  • Rolling-origin backtesting
  • Forecast metrics (MAE, MAPE, MASE)
  • Prediction intervals
  • Deep forecasting models

Mini project

Forecast daily sales or energy demand 14 days ahead: compare seasonal naive, ETS and LightGBM with lag features in a 6-fold rolling backtest, and plot forecasts with 80 percent intervals.

Check yourself

Why is a random K-fold split invalid for time series, and how does rolling-origin evaluation fix it?

Free resources