どの ARMA モデルが最適?
第3章で学んだとおり、赤池情報量規準(AIC)はパラメータ数が異なるモデルを比較するために使えます。あてはまりの良さを測りつつ、パラメータが多いモデルには過学習を避けるためのペナルティを与えます。AIC は値が低いほど良いモデルです。
AIC を基準に、気温データに AR(1)、AR(2)、ARMA(1,1) を当てはめ、どのモデルが最も適合しているかを確認しましょう。AR(2) と ARMA(1,1) は、AR(1) よりパラメータが1つ多いモデルです。
年間の気温変化は DataFrame chg_temp に入っています。
この演習はコースの一部です
Pythonで学ぶ時系列解析
演習の手順
- 各 ARMA モデルについて、
ARIMAクラスのインスタンスを作成し、データとorder=(p,d,q)を渡します。pは自己回帰の次数、qは移動平均の次数、dは系列を差分化した回数です。 - メソッド
.fit()を使ってモデルを学習します。 - 結果オブジェクトの
.aic要素にある AIC の値を出力します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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: ", ___)