Model diagnostics

ARIMA Models in Python

James Fulton

Climate informatics researcher

Introduction to model diagnostics

  • How good is the final model?
ARIMA Models in Python

Residuals

ARIMA Models in Python

Residuals

# Fit model
model = ARIMA(df, order=(p,d,q))
results = model.fit()

# Assign residuals to variable residuals = results.resid
2013-01-23    1.013129
2013-01-24    0.114055
2013-01-25    0.430698
2013-01-26   -1.247046
2013-01-27   -0.499565
       ...         ...
ARIMA Models in Python

Mean absolute error

How far our the predictions from the real values?

mae = np.mean(np.abs(residuals))
ARIMA Models in Python

Plot diagnostics

If the model fits well the residuals will be white Gaussian noise

# Create the 4 diagostics plots
results.plot_diagnostics()
plt.show()

ARIMA Models in Python

Residuals plot

ARIMA Models in Python

Residuals plot

ARIMA Models in Python

Histogram plus estimated density

ARIMA Models in Python

Normal Q-Q

ARIMA Models in Python

Correlogram

ARIMA Models in Python

Summary statistics

print(results.summary())
...
===================================================================================
Ljung-Box (Q):                       32.10   Jarque-Bera (JB):                 0.02
Prob(Q):                              0.81   Prob(JB):                         0.99
Heteroskedasticity (H):               1.28   Skew:                            -0.02
Prob(H) (two-sided):                  0.21   Kurtosis:                         2.98
===================================================================================
  • Prob(Q) - p-value for null hypothesis that residuals are uncorrelated
  • Prob(JB) - p-value for null hypothesis that residuals are normal
ARIMA Models in Python

Let's practice!

ARIMA Models in Python

Preparing Video For Download...