Lag Features For ML Forecasting
To use a general model like gradient boosting on time series, you reshape the problem into a supervised table. Lag features are the key trick.
Building lag features
- A lag column holds the value from a fixed number of steps ago, such as yesterday or last week.
- Each row predicts the current value using these past values as inputs.
- You can add several lags so the model sees a short window of recent history.
Beyond raw lags
Rich features sharpen the model.
- Rolling statistics: the mean or standard deviation over a recent window.
- Calendar features: day of week, month, or a holiday flag to capture seasonality.
- Difference features: the change from a prior step to highlight momentum.
Why this matters
Once the series is a table of features and targets, any regression model applies. This unlocks tree ensembles and other flexible learners. The cost is care: you must build features using only past data so no future information leaks into a row.
Key idea
Lag and rolling features turn a series into a supervised table, letting general regression models forecast as long as no future data leaks in.