0
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')

如上所示,我尝试使用 holt-winters 模型进行预测,但我不断收到此错误。 错误发生在 pred 行表示“'start参数无法与与数据索引相关的位置匹配。” ,我想如何处理这个错误?

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

4

1 回答 1

0

这里看来,开始、结束必须是 int、str 或 datetime。如果我做

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

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

于 2019-11-30T10:47:15.700 回答