使用python和statsmodels进行简单的指数平滑

时间:2018-11-01 15:06:57

标签: python time-series statsmodels

我试图用Python实现SES模型来预测时间序列数据。但是,我还没有成功。验证代码:

df = pd.read_csv('C:/UniBw/7_HT2018/Bachelorarbeit/data/average-annual-temperature-centr.csv', nrows = 121)
train = df[:101]
test = df[100:]

#Aggregating the dataset at yearly level
df.Timestamp = pd.to_datetime(df.Year,format='%Y',errors='ignore') 
df.index = df.Timestamp
df = df.resample('365D').mean()
test.Timestamp = pd.to_datetime(test.Year,format='%Y',errors='ignore') 
test.index = test.Timestamp 
test = test.resample('365D').mean()

from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
y_hat_avg = test.copy()
fit2 = SimpleExpSmoothing(np.asarray(train['temperature'])).fit(smoothing_level=0.6)
y_hat_avg['temperature'] = fit2.forecast(len(test))
plt.figure(figsize=(16,8))
plt.plot(y_hat_avg['temperature'], label='SES')
plt.plot(df.temperature, label='Actual')
plt.legend(loc='best')
plt.title('Average Annual Temperature, central England, 1851 – 1970 (yearly data)')
plt.grid(True)
plt.show()

还有,我所拥有的:enter image description here

有人可以帮我吗?

0 个答案:

没有答案