哪個 ARMA 模型最好?
回想第 3 章所述,赤池資訊量準則(AIC)可用來比較具有不同參數數量的模型。它同時衡量擬合優度,並對參數較多的模型加上懲罰,以避免過度擬合。AIC 越低越好。
請將溫度資料分別配適 AR(1)、AR(2) 與 ARMA(1,1),並用 AIC 判斷哪個模型最合適。AR(2) 與 ARMA(1,1) 相較於 AR(1) 各多 1 個參數。
年度溫度變化已放在 DataFrame chg_temp 中。
本練習屬於課程
Python 中的時間序列分析
練習說明
- 對每個 ARMA 模型,建立
ARIMA類別的實例,傳入資料與order=(p,d,q)。p是自我迴歸(autoregressive)階數;q是移動平均(moving average)階數;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: ", ___)