Search code examples
pythonmachine-learningtime-seriesstatsmodelsarima

StatsModels SARIMAX with exogenous variables - how to extract exogenous coefficients


I fit a statsmodels SARIMAX model to my data, leveraging some exogenous variables.

How to extract the fitted regression parameters for the exogenous variables? It is clear per documentation how to get AR, MA coefficients, but nothing about exog coefficients. Any advice?

Code snippet below:

#imports
import pandas as pd
from statsmodels.tsa.statespace.sarimax import SARIMAX
#X and Y variables, index as dates, X has several columns with exog variables
X = df[factors]
Y = df[target]

#lets fit it
model= SARIMAX(endog=Y[:'2020-04-13'], exog = X[:'2020-04-13'], order = (5,2,1))

#fit the model
model_fit = model.fit(disp=0)
#get AR coefficients
model_fit.polynomial_ar

Solution

  • There isn't a specific attribute for this, but you can always access all parameters using the model_fit.params attribute.

    For the SARIMAX model, the exog parameters are always right after any trend parameters, so the following should always work:

    exog_params = model_fit.params[model.k_trend:model.k_trend + model.k_exog]