liveBook · Manning

Lag

As explained in Machine Learning System Design

A feature or time-series value obtained from an earlier time point relative to the prediction time.

A lag turns an earlier value in a time series into a feature for a later prediction. For sales forecasting, that might mean using an item’s sales from a previous day or week to predict its future sales. Lags are one option alongside rolling-window aggregates such as means, maxima, and minima. section 11.1.2 section 8.6.1

A weekly sales baseline

To predict an item’s sales on September 8, use its actual sales at the same grocery on September 1. Going back a full week rather than one day accounts for weekly seasonality and the possibility that recent sales data arrives late. section 8.6.1

More lags can capture more complex patterns and seasonalities, but they also make overfitting easier. Compare validation error across choices such as the previous one to three days versus the previous 30 days, using a model-size-versus-error curve. Lag count is a model-complexity choice, not a reason to include every available past value. section 9.4.1

A linear forecasting baseline can combine multiple lags with rolling sums, averages, medians, extrema, or quantiles. The same approach can use past values of changing inputs such as price, revenue, and customer counts—not just past sales. section 8.6.1

How Machine Learning System Design covers it

How deep it goes
Defines the time shift and works through a weekly baseline and lag-count selection, without specifying an implementation.
Examples
Uses prior-week item sales for a dated forecast and contrasts three daily lags with 30.
What you can do after
Practice/perform lag selection by comparing validation error across lag counts while watching for overfitting.
How it connects
Connects lags to time-series forecasting, feature engineering, rolling-window aggregates, seasonality, learning curves, and overfitting.

Also explained in

Compare how 5 books explain lag →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning System Design. The section links point to the parts of the book it draws on.