冬冬模型的预报

时间:2019-11-30 02:31:52

标签: python time-series statsmodels forecasting holtwinters

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from statsmodels.tsa.holtwinters import ExponentialSmoothing

df =pd.read_csv(r"C:\Users\USER\PycharmProjects\mysqlconnection\mul.csv",
                 index_col='finalYears')

)
df.index.freq = 'M'
train, test = df.iloc[:20, 0], df.iloc[20:, 0]
model = ExponentialSmoothing(train, seasonal='mul', seasonal_periods=4).fit()
pred = model.predict(start=test.index[0], end=test.index[-1])

plt.plot(train.index, train, label='Train')
plt.plot(test.index, test, label='Test')
plt.plot(pred.index, pred, label='Holt-Winters')
plt.legend(loc='best')

我尝试使用霍尔特-冬天模型进行预测,如上所示,但我一直收到此错误。 在pred行发生的错误表明“'start参数无法与与数据索引相关的位置匹配。” ,我要如何处理此错误?

这是我的数据。我将数据分为一年1的季度

1 个答案:

答案 0 :(得分:0)

here起,开始,结束似乎必须是int,str或datetime。如果我这样做

start = 20
end = test.shape[0]+20
pred = model.predict(start=start, end=end)

然后运行预测。 read_csv可能已将您的索引列转换为int / str / datetime以外的内容。