0

是否可以在自动 arima 预测模型中使用布尔外生变量以及如何应用它们

数据表

读取 & 解析和删除空值 &

raw_csv_data = pd.read_csv("WFMS_Dump_7.csv")
df_comp = raw_csv_data.copy()
df_comp.Date= pd.to_datetime(df_comp.Date ,dayfirst= "True")
df_comp.set_index("Date" , inplace = True)
df_comp= df_comp.asfreq("b")
df_comp=df_comp.fillna(method = "ffill")

检查数据

df_comp.head()
df_comp.describe()
df_comp.isna().sum()

创建退货

df_comp['ret_A'] = df_comp.A.pct_change(1).mul(100)
df_comp['ret_B'] = df_comp.B.pct_change(1).mul(100)
df_comp['ret_C'] = df_comp.C.pct_change(1).mul(100)
df_comp['ret_TTS'] = df_comp.TTS.pct_change(1).mul(100)

划分测试数据

size = int(len(df_comp)*0.8)
df=df_comp.iloc[:size]
df_test =df_comp.iloc[size:]

创建模型 Auto Arima

start_date = "2020-07-01"
end_date = "2020-08-30"
#Start & End Date Must Be Part of your data set
df_auto_pred = pd.DataFrame(model_auto.predict(n_periods = len(df_test[start_date:end_date]),
                            exogenous = df_test[['ret_A', 'ret_B', 'ret_C']][start_date:end_date]),
                            index = df_test[start_date:end_date].index)

预测结果

df_auto_pred = pd.DataFrame(model_auto.predict(n_periods = len(df_test[start_date:end_date]),
                            exogenous = df_test[['ret_A', 'ret_B', 'ret_C']][start_date:end_date]),
                            index = df_test[start_date:end_date].index)

结果

df_auto_pred.plot(figsize = (20,5), color = "red")
df_test.ret_TTS[start_date:end_date].plot(color = "blue")
plt.title("Auto Model Predictions vs Real Data", size = 24)
plt.show()
4

0 回答 0