I have written a program that should forecast the value using exponential smoothing. I have got data for 6 months (from April to September). Based on these 6 months, I want to forecast for the next 6 months (i.e., from October to March).
Here is my code:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from statsmodels.tsa.holtwinters import ExponentialSmoothing
d = {'Month':['April','May','June','July','August','September'],'Value':[2.868,7.205,13.349,20.115,22.769,23.981]}
df = pd.DataFrame(data=d)
model = ExponentialSmoothing(df['Value'],trend='mul',seasonal='mul',seasonal_periods = 6).fit()
predict = model.forecast(6)
However, when I see the predicted value its all are Nans
. I am not sure where I'm making the mistake. Could anyone help in rectifying the issue?
Looking at the documentation, seasonal_periods
is the number of periods in a seasonal cycle.
If you look at the equation for Holt-Winters (e.g., here), it includes a term for seasonality which is shifted by m
steps (where m
is equal to seasonal_periods
). This means, that to make a prediction where seasonal_periods=6
, you need to have the input value in the data 6
timesteps earlier.
Since the data only contains 6
data points there is no way to make any prediction.
Possible solutions:
seasonal_periods
argument or change it.