开始使用免费开始使用

估计模型阶数:信息准则

识别模型阶数的另一种方法是查看 Akaike 信息准则(AIC)和贝叶斯信息准则(BIC)。这些度量基于估计参数计算拟合优度,但会对模型中的参数数量施加惩罚函数。您将使用上一个练习中保存为 simulated_data_2 的 AR(2) 模拟数据,在 AR(p) 中将阶数 p 从 0 变化到 6,并计算对应的 BIC。

本练习是课程的一部分

Python 中的时间序列分析

查看课程

练习说明

  • 导入用于估计参数并计算 BIC 的 ARIMA 模块。
  • 初始化一个 numpy 数组 BIC,用于存储每个 AR(p) 模型的 BIC。
  • 遍历阶数 p(p = 0,…,6)。
    • 对于每个 p,将数据拟合为阶数为 p 的 AR 模型。
    • 对于每个 p,使用 res.bic 属性(不加括号)保存 BIC 值。
  • 将 BIC 随 p 的变化绘图(作图时跳过 p=0,只绘制 p=1,…,6)。

交互式实操练习

通过完成这段示例代码来试试这个练习。

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

# Fit the data to an AR(p) for p = 0,...,6 , and save the BIC
BIC = np.zeros(7)
for p in range(7):
    mod = ARIMA(simulated_data_2, order=(___,___,___))
    res = mod.fit()
# Save BIC for AR(p)    
    BIC[p] = res.___
    
# Plot the BIC as a function of p
plt.plot(range(1,7), BIC[1:7], marker='o')
plt.xlabel('Order of AR Model')
plt.ylabel('Bayesian Information Criterion')
plt.show()
编辑并运行代码