0

I have a file with 5 years worth of daily data from 2015 to 2019 (31/12/2019) and I need to forecast daily values for 2021; I use statsmodels.tsa.holtwinters.ExponentialSmoothing and until now I was able to forecast it by also forecasting year 2019 and 2020. Is it possible to forecast 2021 without doing it for 2020?

Here's what I have in terms of code:

fit1 = ExponentialSmoothing(train[colval],seasonal_periods=730,trend=trend, seasonal=seasonal,).fit()
prediction_result = fit1.forecast(365)

With the above code, the forecast also starts just after the training data set, is it normal?

This is how I split my data: 2015-2018 train and 2019 for test

  • 1
    You can check [predict](https://www.statsmodels.org/stable/generated/statsmodels.tsa.holtwinters.ExponentialSmoothing.predict.html#statsmodels.tsa.holtwinters.ExponentialSmoothing.predict). You can pass the start date and end date to predict. However you need your series to have datetimeindex with freq variable defined – max12525k Oct 12 '21 at 07:05
  • @max12525k from what i have tested, start date must match an existing index from the dataset and the one i have does not contain any 2021 dates. should i fill it with dates but no values maybe? – Mihai Domocoş Oct 12 '21 at 07:09

1 Answers1

2

You can use predict function to forecast for any date if you feed the datetimeindex based series to ExponentialSmoothing while training which has frequency set. AirPassengers data has frequency set to Month start. The data contained in AirPassengers is for 1949 - 1960.

Please refer below example for details:

import pandas as pd 
df = pd.read_csv('AirPassengers.csv')
df['Month'] = pd.to_datetime(df['Month'])
df = df.set_index('Month')
from statsmodels.tsa.api import ExponentialSmoothing
es = ExponentialSmoothing(df).fit()
es.predict('2021-05-01', '2021-08-01')

you will have the output as follows:

0
2021-05-01 00:00:00 431.792
2021-06-01 00:00:00 431.792
2021-07-01 00:00:00 431.792
2021-08-01 00:00:00 431.792

I hope this answers your question.

max12525k
  • 171
  • 3