Output graph 我尝试使用冬冬模型进行预测,但是得到的预测与我的预期不一致。我已经附上了输出图。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.tsa
from statsmodels.tsa.holtwinters import ExponentialSmoothing
#importing data
df=pd.read_csv('####.csv')
df=df.dropna()
df['Date']=pd.to_datetime(df['Date'],errors='coerce',format='%d-%m-%y')
df.set_index(['Date'],inplace=True)
print(df)
train=df[0:24]
#train['Date']=pd.to_datetime(train['Date'],errors='coerce',format='%m-%d-%y')
test=df[24:]
test=test.dropna()
#test['Date']=pd.to_datetime(test['Date'],errors='coerce',format='%m-%d-%y')
y_hat_avg = test.copy()
y_hat_avg=y_hat_avg.dropna()
model = ExponentialSmoothing(np.asarray(train['REVPAR']),seasonal_periods=12 ,seasonal='mul').fit()
y_hat_avg['Holt_Winter'] = model.predict(start=24, end=30)
#y_hat_avg['Holt_Winter'] = model.forecast(len(test))
print(y_hat_avg)
plt.figure(figsize=(16,8))
pd.plotting.register_matplotlib_converters()
plt.plot( train.index,train['REVPAR'], label='Train')
plt.plot( test.index,test['REVPAR'], label='Test')
plt.plot(y_hat_avg.index,y_hat_avg['Holt_Winter'], label='Holt_Winter')
plt.legend(loc='best')
plt.show()
预测值与测试值不符