elsag
elsag

Reputation: 41

Get p,q,d and P, D, Q, m values from auto-arima summary

I have built multiple SARIMA models using auto-arima from pyramid ARIMA and would like to extract the p,q,d and P, D, Q, m values from the model and assign them to variables so that I can use them in a future model.

I can use model.summary() to see the values, but this isn't much good to me because I need to assign them to a variable.

enter image description here

Upvotes: 0

Views: 4382

Answers (2)

SURAJ YATHINATTI
SURAJ YATHINATTI

Reputation: 1

To get order and seasonal_order values from AutoARIMA model summary, we can use get_params().
https://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html

Click on the below links to get a better picture.

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() 

Upvotes: 0

Vinod Sawant
Vinod Sawant

Reputation: 623

You can use following technique to solve your problem,

#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)

Final output : enter image description here Click here for my model.summary() output.

In this way you can store parameter values of all your models with help of loop.

Upvotes: 2

Related Questions