从自动取景摘要中获取p,q,d和P,D,Q,m值

时间:2019-11-28 05:02:09

标签: python arima pyramid-arima

我已经使用金字塔ARIMA中的自动别名建立了多个SARIMA模型,并希望从模型中提取p,q,d和P,D,Q,m值并将它们分配给变量,以便我可以使用它们在未来的模型中。

我可以使用model.summary()来查看值,但是这对我来说并不太好,因为我需要将它们分配给变量。

enter image description here

2 个答案:

答案 0 :(得分:2)

您可以使用以下技术来解决您的问题,

#In this case I have used model of ARIMA,
#You can convert model.summary in string format and find its parameters
#using regular expression.

import re
summary_string = str(model.summary())
param = re.findall('ARIMA\(([0-9]+), ([0-9]+), ([0-9]+)',summary_string)
p,d,q = int(param[0][0]) , int(param[0][1]) , int(param[0][2])
print(p,d,q)

最终输出:enter image description here Click here for my model.summary() output

通过这种方式,您可以在循环的帮助下存储所有模型的参数值。

答案 1 :(得分:0)

要从AutoARIMA模型摘要中获取订单和季节性订单值,我们可以使用get_params()。
https://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html

点击下面的链接以获得更好的图片。

This is the model summary of AUTOARIMA \

model = auto_arima(df_weekly1['Value'], start_p = 1, start_q = 1, 
                      max_p = 3, max_q = 3, m = 12, 
                      start_P = 0, seasonal = True, 
                      d = None, D = 1, trace = True)
model.summary() 

We can get the model summary values using get_params(), the output of the get_params function will be a dict datatype.

get_parametes = model.get_params()
print(type(get_parametes))
get_parametes

Get the required values using Key-Value pair and assign the same to a variable.

order_aa = get_parametes.get('order')
seasonal_order_aa = get_parametes.get('seasonal_order')
print('order:', order_aa)
print('seasonal_order:', seasonal_order_aa)
print('order DTYPE:', type(order_aa))
print('seasonal_order DTYPE:', type(seasonal_order_aa))

model_ss = SARIMAX(train['Col_Name'], 
            order = (order_aa[0], order_aa[1], order_aa[2]),  
            seasonal_order =(seasonal_order_aa[0], 
seasonal_order_aa[1], seasonal_order_aa[2], seasonal_order_aa[3])) 

result_ss = model_ss.fit() 
result_ss.summary()