时间序列中的偏自相关
与自相关类似,偏自相关函数(PACF)衡量时间序列与其滞后版本之间的相关系数。但它在此基础上进一步消除了较早时间点的影响。例如,order 3 的偏自相关表示时间序列(t_1、t_2、t_3、…)与其滞后 3 个时间点的取值(t_4、t_5、t_6、…)之间的相关性,但前提是先剔除了由 1 阶和 2 阶滞后所造成的全部影响。
statsmodels 库中的 plot_pacf() 函数可用于计算并绘制时间序列的偏自相关。
本练习是课程的一部分
用 Python 可视化时间序列数据
练习说明
- 从
statsmodels.graphics导入tsaplots。 - 使用
tsaplots的plot_pacf()函数绘制co2_levels中'co2'列的偏自相关图。 - 将最大滞后设为 24。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import required libraries
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
____
# Display the partial autocorrelation plot of your time series
fig = ____(co2_levels[____], lags=____)
# Show plot
plt.show()