A lagged feature records an earlier value of a variable so a model can use temporal relationships when predicting a later observation. It is especially useful for time-series data, where observations are often autocorrelated rather than independent. section 2.1.1
Use lagged features in two common ways:
- Keep each observation associated with a date or time interval, then create lagged values and use time-appropriate cross-validation. section 2.1.1
- Pivot values from several moments into separate columns, such as sales_month_1, sales_month_2, and later periods, producing a conventional tabular feature set. section 2.1.1
- Combine lagged values with moving averages at different time horizons when preparing features for gradient-boosted decision trees. section 5.2.2
Retail forecasting
A supermarket forecasting dataset can represent earlier sales as separate lagged columns. These features give a gradient-boosted model access to recent and older demand patterns; longer series and careful feature engineering support this approach, while shorter series may favor classical time-series methods. section 2.1.1 section 5.2.2
Figure 2.1 Comparison of IID and non--IID data sequences. The left chart shows IID data, while the right chart illustrates non-IID data, highlighting the sequential correlation patterns.
Compare independent and sequentially correlated data before deciding whether lagged features and time-aware validation are needed. section 2.1.1
