Knowledge Base

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_split
3train, test = train_test_split(data, shuffle=False, test_size=0.2)

1# creating calendar features
2# this feature contains years as numeric values
3data['year'] = data.index.year
4
5# this feature contains weekdays as numeric values
6data['dayofweek'] = data.index.dayofweek

1# forming lag features
2
3data['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 feature
2
3data['rolling_mean'] = data['target'].rolling(5).mean()
Send Feedback
close
  • Bug
  • Improvement
  • Feature
Send Feedback
,