Search code examples
pythonmachine-learningtime-seriesforecastingholtwinters

ExponentialSmoothing - forecast daily data


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


Solution

  • 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.