
An Autoregressive Integrated Moving Average (Arima) model is still one of the most popular and effective ways to forecast time series data. It is a linear model that correlates a series’ past lags, errors, and stationarity to make a theory about the underlying statistical properties of the data. It uses that information to predict future values.
A common way to implement the ARIMA model in Python is by using statsmodels. There are many tutorials surrounding such implementation, and most people with a data-science related degree have gone through this exercise.
If you know the basics of and feel comfortable with the ARIMA model, you might like a library that cuts down on data preparation and the lines of code needed to implement this model. In fact, I can write scripts very quickly that validate and forecast with ARIMA and the results have proved accurate. It all involves using the scalecast package. It is Easy to install:
pip install scalecast
We will be using a monthly passenger counts dataset available on Kaggle with an Open Database license. See the code used in this post here. See the scalecast project on GitHub.
Scalecast
This package is for forecasters who know their models will need to be validated and used to produce forecasts on a future horizon. Maybe you don’t want to spend as much time breaking down the fine details of the model. If that is the case, the basic flow of the code, from importing results, to testing and Forecasting, goes like this:

This model is easy to specify and the individual lines of code are highly interpretable. Of course, this example will give you something akin to a "naïve" forecast, where the statistical properties haven’t really been examined and the model doesn’t really predict anything useful. Therefore, a slightly more complex script, like this, can be employed:


In this process, you would look at the results of several charts, including ACF, PACF, and a seasonal-decomposition plot. You would also interpret the results of statistical tests, like the Augmented Dickey-Fuller and Ljung-Box to see the series’ desired level and the model’s validity. Using the insights discovered, you could try specifying and re-specifying models until you found one you like. Fortunately, the one selected here seems to work well, and it didn’t take me long to find it.
This process overall still requires fewer lines of code than statsmodels might, but it becomes an iterative process that requires human interventions and interpretations of graphs to find the optimal ARIMA orders to make the model useful. Maybe you don’t have time for that and want to automate the human part away.
Full automation
Automation could introduce problems to the modeling process, such as the risk of specifying "noisy" models and models that are statistically unsound. But, the risk might be worth it for you. If that is the case, you can use the following two solutions.
Solution 1 – Set orders with pmdarima’s auto_arima function
Using auto_arima from pmdarima requires installation of the pmdarima package:
pip install pmdarima
Once that is done, you can call the function on a time series and it will find the optimal order for you quickly by minimizing an information criterion, such as AIC, that measures the model’s fit but also penalizes too many parameters that may cause overfitting. I always use the train set only to do this part so that I don’t leak data and overfit. Here is an example using our same dataset and the scalecast process to perform the forecast:


We can see the chosen ARIMA model from auto_arima was (1,1,0)(0,1,0)[12] and that this model also appears to fit well. You can try passing other arguments to the function and a different information criterion to see if you get different results. You can also see this model’s summary stats:
f.regr.summary()

Solution 2 – Grid search the optimal orders in scalecast
If you don’t like the auto_arima function and you still want to automatically find the best model for your series, scalecast itself offers another way to search for optimal ARIMA orders, and that is through a grid search on a validation slice of data.
This may offer advantages to the auto_arima approach as it will actually validate the selected orders on out-of-sample data instead of using information criteria, which aren’t perfect. The grid-search approach also doesn’t require calling in another library to your Python script. The downside is that it can take longer than auto_arima and you won’t be able to iterate through as many models as quickly.
Here is the code for this process:

This code searches through 12 ARIMA models to find the one with the most optimal orders by testing each one’s error on the 12 observations most closely preceding the test-set observations. These 12 observations are excluded from each training iteration. The number 12 can be modified on the first line of the above code. As we can see, this approach also produced excellent results!
Selecting models and exporting results
We have specified four ARIMA models in this script. Which one is the best? We can compare several error and accuracy metrics in scalecast, including RMSE, MAE, MAPE, and R2. I will choose the test-set MAPE performance. First, let’s export the results, including test-set predictions, forecasts, and model statistics, to a dictionary of pandas dataframes.
pd.options.display.max_colwidth = 100
results = f.export(to_excel=True,
excel_name='arima_results.xlsx',
determine_best_by='TestSetMAPE')
We then select some information to see about each model by using this code:
summaries = results['model_summaries']
summaries[
[
'ModelNickname',
'HyperParams',
'InSampleMAPE',
'TestSetMAPE'
]
]

Unsurprisingly, the first ARIMA specified where no orders were selected is clearly the worst. The ARIMA that used the grid search to find its orders is technically the best (3.6% error on the test-set), but all three of the other models are very similar. None of them showed signs of overfitting, as their in-sample and test-set metrics are very close. Let’s see their forecasts all plotted together. They will be ordered by their test-set MAPE performance from best-to-worst.

Exogenous variables – for next time
We have overviewed the use of a seasonal ARIMA (SARIMA) model, but there are other variants of this model available. For example, using exogenous variables, such as holidays or outliers, is possible by adding the desired variables to the object and specifying the Xvars
argument in the manual_forecast()
function, as well as in the grids if using auto_forecast()
. See the documentation for more information.
Conclusion
Specifying and implementing the results of ARIMA has never been easier using the scalecast package. I hope you find the code useful and you are able to set up your own ARIMA processes using this methodology!