我正尝试在python上使用这个函数来模拟我已经构建的SARIMAX模型,statsmodels.tsa.statespace.sarimax.SARIMAX.simulate目的是使用该模型进行蒙特卡洛模拟
当我尝试使用已有的数据将initial_state放在函数上时,就会出现问题
我已经尝试不使用initial_state,模拟的结果似乎很好,但初始点并不是我所期望的。当我尝试放置一个initial_state时,模拟结果呈指数增长。
我使用的是2017- 2019年的日降水量数据
#Define the test model using another set of data, but the same order.
testMdl = smt.SARIMAX(rain_df_daily.y, order = (5, 3, 0), seasonal_order=(1,1,2,12),enforce_stationarity=False,
enforce_invertibility=False)
#Set initial state
#testMdl.initialize_known(rain_df_daily[:'2018-01-01'].y.mean,rain_df_daily[:'2018-01-01'].y.std)
testMdl.initialize_known(sarima_results.predicted_state[:,-2],
sarima_results.predicted_state_cov[:,:,-2])
#Initialize the test model with the coefficients from the fit model:
testMdl = testMdl.filter(sarima_results.params)
#Seems you can also use .smooth() to initialize coefficients, but have not looked into the difference
#exoCopy = exoCopy.smooth(fitMdl.params)
samples = pd.DataFrame(columns = range(0,50)) #initialize obs. sample df
for sample in range(0, 50): #For each sample
#samples[sample] = testMdl.simulate(24, initial_state=mdlExo.predicted_state[:,-1])
samples[sample] = testMdl.simulate(40, initial_state = rain_df_daily['2018-02-21':].y)我预计结果会接近预测的平均值。
发布于 2019-09-20 20:33:23
我认为你的模型的问题在于指定的顺序参数,而不是用于模拟的初始值。
例如,根据降雨量数据拟合的更简单的模型
model = SARIMAX(df,
order=(1, 0, 1),
trend='n',
seasonal_order=(1, 2, 1, 5),
enforce_stationarity=False,
enforce_invertibility=False).fit()
model.forecast(60).plot()生成结果
和模拟
samples = []
for sample in range(50):
samples.append(model.simulate(30, initial_state=model.predicted_state[:, -1]))
sns.lineplot(data=samples)结果:
这肯定不是一个很好的模型,但结果与预测均值相差不远。
https://stackoverflow.com/questions/55618942
复制相似问题