开始使用免费开始使用

先"热热身":查看自相关

由于气温序列 temp_NY 是带漂移的随机游走,请先做一阶差分以使其平稳。然后计算样本 ACF 和 PACF。这将为模型阶数提供一些参考。

本练习是课程的一部分

Python 中的时间序列分析

查看课程

练习说明

  • 导入用于绘制样本 ACF 和 PACF 的模块
  • 使用 pandas 的 .diff() 方法对数据框 temp_NY 做一阶差分
  • 创建两个子图用于绘制 ACF 和 PACF
    • 绘制差分后序列的样本 ACF
    • 绘制差分后序列的样本 PACF

交互式实操练习

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

# Import the modules for plotting the sample ACF and PACF
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

# Take first difference of the temperature Series
chg_temp = ___.___
chg_temp = chg_temp.dropna()

# Plot the ACF and PACF on the same page
fig, axes = plt.subplots(2,1)

# Plot the ACF
plot_acf(___, lags=20, ax=axes[0])

# Plot the PACF
plot_pacf(___, lags=20, ax=axes[1])
plt.show()
编辑并运行代码