โมเดล ARMA แบบใดดีที่สุด?
จากที่เรียนในบทที่ 3 Akaike Information Criterion (AIC) ใช้เปรียบเทียบโมเดลที่มีจำนวนพารามิเตอร์แตกต่างกัน โดยวัดความเหมาะสมของโมเดล แต่จะเพิ่มบทลงโทษสำหรับโมเดลที่มีพารามิเตอร์มากขึ้น เพื่อป้องกันการ overfitting ค่า AIC ที่ต่ำกว่าหมายถึงโมเดลที่ดีกว่า
ลอง fit ข้อมูลอุณหภูมิกับโมเดล AR(1), AR(2) และ ARMA(1,1) แล้วดูว่าโมเดลใดเหมาะสมที่สุดโดยใช้เกณฑ์ AIC โมเดล AR(2) และ ARMA(1,1) มีพารามิเตอร์มากกว่า AR(1) อยู่หนึ่งตัว
ข้อมูลการเปลี่ยนแปลงอุณหภูมิรายปีอยู่ใน DataFrame chg_temp
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์อนุกรมเวลาด้วย Python
คำแนะนำการฝึกหัด
- สำหรับโมเดล ARMA แต่ละตัว ให้สร้าง instance ของคลาส
ARIMAโดยส่งข้อมูลและorder=(p,d,q)pคือ autoregressive order,qคือ moving average order และdคือจำนวนครั้งที่ทำ differencing กับ series - fit โมเดลโดยใช้เมธอด
.fit() - แสดงค่า AIC ซึ่งอยู่ใน element
.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: ", ___)