-
Book Overview & Buying
-
Table Of Contents
Machine Learning for Time Series with Python - Second Edition
By :
While calendar features capture fixed, repeating patterns, the dynamics of a time series also depend on its own recent history. Advanced feature engineering techniques are required to model concepts like momentum, trend, and volatility. These features capture the temporal dependencies that are the hallmark of time series data.
One of the most fundamental properties of many time series is autocorrelation: the value at a given time is correlated with values at previous times. In a regression framework, the most direct way to capture this is by creating lag features. A lag feature is simply a value from a previous time step. For example, sales_lag_1 would be the sales from the previous day, and sales_lag_7 would be the sales from the same day of the previous week.
Creating these features in pandas is done using the .shift() method. A critical detail when working with panel data is to compute these lags independently for each time series (in M5, each...