Time Series Forecasting
Glossary
Forecast horizon: The length of time into the future for which the forecast is prepared.
Time series forecasting: a model which predicts the future values of a time series based on previous data.
Practice
1# splitting data into training and test sets for time series (without shuffling)2from sklearn.model_selection import train_test_split3train, test = train_test_split(data, shuffle=False, test_size=0.2)
1# creating calendar features2# this feature contains years as numeric values3data['year'] = data.index.year45# this feature contains weekdays as numeric values6data['dayofweek'] = data.index.dayofweek
1# forming lag features23data['lag_1'] = data['target'].shift(1)4data['lag_2'] = data['target'].shift(2)5data['lag_3'] = data['target'].shift(3)
1# adding the rolling mean feature23data['rolling_mean'] = data['target'].rolling(5).mean()