Automation and saving

ARIMA Models in Python

James Fulton

Climate informatics researcher

Searching over model orders

import pmdarima as pm
results = pm.auto_arima(df)
Performing stepwise search to minimize aic
 ARIMA(2,0,2)(1,1,1)[12] intercept   : AIC=inf, Time=3.33 sec
 ARIMA(0,0,0)(0,1,0)[12] intercept   : AIC=2648.467, Time=0.062 sec
 ARIMA(1,0,0)(1,1,0)[12] intercept   : AIC=2279.986, Time=1.171 sec

 ...

 ARIMA(3,0,3)(1,1,1)[12] intercept   : AIC=2173.508, Time=12.487 sec
 ARIMA(3,0,3)(0,1,0)[12] intercept   : AIC=2297.305, Time=2.087 sec

Best model:  ARIMA(3,0,3)(1,1,1)[12]
Total fit time: 245.812 seconds
ARIMA Models in Python

pmdarima results

print(results.summary())

results.plot_diagnostics()

ARIMA Models in Python

Non-seasonal search parameters

ARIMA Models in Python

Non-seasonal search parameters

results = pm.auto_arima( df,             # data

d=0, # non-seasonal difference order
start_p=1, # initial guess for p start_q=1, # initial guess for q
max_p=3, # max value of p to test max_q=3, # max value of q to test )
1 https://www.alkaline-ml.com/pmdarima/modules/generated/pmdarima.arima.auto_arima.html
ARIMA Models in Python

Seasonal search parameters

results = pm.auto_arima( df,             # data
                         ... ,          # non-seasonal arguments 
                         seasonal=True,  # is the time series seasonal

m=7, # the seasonal period
D=1, # seasonal difference order
start_P=1, # initial guess for P start_Q=1, # initial guess for Q
max_P=2, # max value of P to test max_Q=2, # max value of Q to test )
ARIMA Models in Python

Other parameters

results = pm.auto_arima( df,                     # data    
                         ... ,                   # model order parameters     

information_criterion='aic', # used to select best model
trace=True, # print results whilst training
error_action='ignore', # ignore orders that don't work
stepwise=True, # apply intelligent order search )
ARIMA Models in Python

Saving model objects

# Import
import joblib 
# Select a filepath
filepath ='localpath/great_model.pkl'

# Save model to filepath
joblib.dump(model_results_object, filepath)
ARIMA Models in Python

Saving model objects

# Select a filepath
filepath ='localpath/great_model.pkl'

# Load model object from filepath
model_results_object = joblib.load(filepath) 
ARIMA Models in Python

Updating model

# Add new observations and update parameters
model_results_object.update(df_new)
ARIMA Models in Python

Update comparison

ARIMA Models in Python

Let's practice!

ARIMA Models in Python

Preparing Video For Download...