问题描述
我正在研究一个项目,以分析covid 19如何影响发货量,并且我正在使用SARIMAX预测未来几个月的发货量。但是,我不断得到如下所示的结果:
# Shipment volume data (monthly basis)
df_monthly = df.loc[:'2020-06-30'].resample('MS').sum()
df_monthly
# covid 19 data (monthly basis)
df_covid_monthly = df_covid.loc[:'2020-06-30']
df_covid_monthly = df_covid.resample('MS').sum()
df_covid_monthly
# SARIMAX model
model= SARIMAX(df_monthly,exog=df_covid_new,order=(2,1,1),enforce_invertibility=False,enforce_stationarity=False)
results= model.fit()
# Prediction
pred = results.get_prediction(start='2020-06-01',end='2020-12-01',dynamic=False,index=None,exog=df_covid_monthly['2020-02-01':],extend_model=None,extend_kwargs=None)
pred
输出:
<statsmodels.tsa.statespace.mlemodel.PredictionResultsWrapper at 0x27b64b4a608>
解决方法
这是预期的输出。您需要访问PredictionResultsWrapper
以外的属性,例如predicted_mean
。
请参阅开发文档:https://www.statsmodels.org/devel/generated/statsmodels.tsa.base.prediction.PredictionResults.html
请注意,您不会看到Wrapper
,因为这只是一个附加索引并进行内务处理的类。 PredictionResults
是返回的主要类。
经过多次阅读并尝试修改我的代码后,我终于可以得到我的预测结果。这是我所做的更改:model = sm.tsa.SARIMAX(endog=df_monthly,order=(1,1,1),seasonal_order=(0,12))
model_fit = model.fit()
prediction = model_fit.predict(start='2020-07-01',end='2020-1201',dynamic=False,exog=df_covid_monthly,extend_kwargs=None)