liveBook · Manning

Lagged feature

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

A lagged value is a time-series feature formed from an earlier observation of a variable.

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

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Defines two feature-construction patterns and recommends time-aware validation, but does not detail lag calculation or implementation code.
Examples
Uses sales_month_1-style columns and supermarket-network forecasting to illustrate temporal feature engineering.
What it assumes
Assumes a variable observed across time and teaches why non-independent observations require explicit temporal features.
What you can do after
Apply it via time-based feature engineering and choose validation or forecasting methods appropriate to the resulting data structure.
How it connects
Connects lagged features with time series, autocorrelation, covariates, moving averages, cross-validation, and gradient boosting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.