Aan de slagGa gratis aan de slag

Which ARMA Model is Best?

Recall from Chapter 3 that the Akaike Information Criterion (AIC) can be used to compare models with different numbers of parameters. It measures goodness-of-fit, but places a penalty on models with more parameters to discourage overfitting. Lower AIC scores are better.

Fit the temperature data to an AR(1), AR(2), and ARMA(1,1) and see which model is the best fit, using the AIC criterion. The AR(2) and ARMA(1,1) models have one more parameter than the AR(1) has.

The annual change in temperature is in a DataFrame chg_temp.

Deze oefening maakt deel uit van de cursus

Time Series Analysis in Python

Cursus bekijken

Oefeninstructies

  • For each ARMA model, create an instance of the ARIMA class, passing the data and the order=(p,d,q). p is the autoregressive order; q is the moving average order; d is the number of times the series has been differenced.
  • Fit the model using the method .fit().
  • Print the AIC value, found in the .aic element of the results.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import the module for estimating an ARIMA model
from statsmodels.tsa.arima.model import ARIMA

# Fit the data to an AR(1) model and print AIC:
mod_ar1 = ARIMA(chg_temp, order=(___, 0, 0))
res_ar1 = mod_ar1.fit()
print("The AIC for an AR(1) is: ", res_ar1.aic)

# Fit the data to an AR(2) model and print AIC:
mod_ar2 = ARIMA(chg_temp, order=(___, ___, ___))
res_ar2 = mod_ar2.___
print("The AIC for an AR(2) is: ", res_ar2.aic)

# Fit the data to an ARMA(1,1) model and print AIC:
mod_arma11 = ___
res_arma11 = ___
print("The AIC for an ARMA(1,1) is: ", ___)
Code bewerken en uitvoeren