开始使用免费开始使用

哪个 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 为自回归阶数;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: ", ___)
编辑并运行代码