首页 > 解决方案 > 从 ARIMAX 模型中提取参数系数和 p 值(python pyflux 包)

问题描述

我正在使用 pyflux ARIMAX 模型,我想提取参数系数和 p 值。我浏览了文档,但找不到任何东西。我尝试了 model.params 但它给了我以下错误。我也尝试过model.coeff_,但遇到了类似的错误。任何帮助是极大的赞赏。谢谢你。


() ----> 1 model.params 中的 AttributeError Traceback (最近一次调用最后一次)

AttributeError:“MLEResults”对象没有属性“params”

标签: python-3.xparameterstime-seriesp-valuecoefficients

解决方案


使用示例这个例子你得到表

>>> model = pf.ARIMAX(data=data, formula='drivers~seat_belt+oil_crisis', ar=1, ma=1, family=pf.Normal())
... x = model.fit("MLE")
... x.summary()

Normal ARIMAX(2,0,1)                                                                                      
======================================================= ==================================================
Dependent Variable: drivers                             Method: MLE                                       
Start Date: 1969.16666666667                            Log Likelihood: -1288.9807                        
End Date: 1984.91666666667                              AIC: 2591.9615                                    
Number of observations: 190                             BIC: 2614.6907                                    
==========================================================================================================
Latent Variable                          Estimate   Std Error  z        P>|z|    95% C.I.                 
======================================== ========== ========== ======== ======== =========================
AR(1)                                    1.4031     0.0694     20.2033  0.0      (1.267 | 1.5392)         
AR(2)                                    -0.4058    0.0599     -6.7751  0.0      (-0.5231 | -0.2884)      
MA(1)                                    -0.8534    0.0429     -19.9112 0.0      (-0.9374 | -0.7694)      
Beta 1                                   0.0099     39.506     0.0003   0.9998   (-77.4218 | 77.4417)     
Beta seat_belt                           0.0021     12.3407    0.0002   0.9999   (-24.1856 | 24.1897)     
Beta oil_crisis                          0.0027     4.3974     0.0006   0.9995   (-8.6162 | 8.6216)       
Normal Scale                             227.6325                                                         
==========================================================================================================

获取Latent Variable表行名称和索引:

>>> ind = x.z.z_indices

{'AR(1)': {'start': 0, 'end': 0}, 'AR(2)': {'start': 1, 'end': 1}, 'MA(1)': {'start': 2, 'end': 2}, 'Beta 1': {'start': 3, 'end': 3}, 'Beta seat_belt': {'start': 4, 'end': 4}, 'Beta oil_crisis': {'start': 5, 'end': 5}, 'Normal Scale': {'start': 6, 'end': 6}}

使用它们来获取EstimateStd Error

>>> est = x.z.z_list[ind['AR(1)']['start']].value
... se = x.z.z_list[ind['AR(1)']['start']].std
... print(est, se)

1.4030704563076553 0.0694474441044986

您现在可以计算 95% 置信区间:

>>> est - 1.96 * se

1.266953465862838

>>> est + 1.96 * se

1.5391874467524724

推荐阅读