首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SARIMAX创建仿真

SARIMAX创建仿真
EN

Stack Overflow用户
提问于 2019-04-11 02:15:36
回答 1查看 627关注 0票数 0

我正尝试在python上使用这个函数来模拟我已经构建的SARIMAX模型,statsmodels.tsa.statespace.sarimax.SARIMAX.simulate目的是使用该模型进行蒙特卡洛模拟

当我尝试使用已有的数据将initial_state放在函数上时,就会出现问题

我已经尝试不使用initial_state,模拟的结果似乎很好,但初始点并不是我所期望的。当我尝试放置一个initial_state时,模拟结果呈指数增长。

我使用的是2017- 2019年的日降水量数据

代码语言:javascript
复制
#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)

我预计结果会接近预测的平均值。

EN

回答 1

Stack Overflow用户

发布于 2019-09-20 20:33:23

我认为你的模型的问题在于指定的顺序参数,而不是用于模拟的初始值。

例如,根据降雨量数据拟合的更简单的模型

Rainfall data

代码语言:javascript
复制
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()

生成结果

Simpler fit

和模拟

代码语言:javascript
复制
samples = []
for sample in range(50): 
    samples.append(model.simulate(30, initial_state=model.predicted_state[:, -1]))

sns.lineplot(data=samples)

结果:

Simulation

这肯定不是一个很好的模型,但结果与预测均值相差不远。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55618942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档