If you’ve landed here, chances are you’re implementing a statsmodels SARIMAX time series model, and you’re looking for an easy way to identify all of the best parameters. And I have some excellent news for you…you’ve landed in the right place!

In this tutorial, you will learn how to run an easy grid search to find the best parameters for your statsmodel SARIMAX time series model. Or you can just copy and paste the code — even easier!

For our SARIMAX model, there are seven sub-parameters total, which on their own would be no easy feat to calculate. However, with a few simple lines of code, we can create a custom grid search that gives us a list of optimal parameters, sorted by users choice of selection criterion (AIC or BIC).

### Selection Criterion

Let’s start with selection criterion. The two choices here are AIC and BIC. These stand for Akaike information criterion and Bayesian information criterion, respectively. And they select for the model that explains the greatest amount of variation using the fewest possible independent variables. [1] The way they calculate this is by using Maximum Likelihood Estimation (MLE), and they both penalize a model for having increasing numbers of variables to prevent overfitting.

There is a lot of discussion around which one is the best to use. BIC will penalize a model more strongly for having an increasing number of variables. If there is more variation expected in future data sets or multiple data sets that the model will be applied to, then I recommend using BIC. As I did here. However, there isn’t a huge difference, and AIC tends to be common, so really the choice is all yours.

#statsmodels #time-series-forecasting #data-science #sarimax #time-series-analysis