自相关与偏自相关

用 Python 可视化时间序列数据

Thomas Vincent

Head of Data Science, Getty Images

时间序列中的自相关

  • 自相关是时间序列与其滞后副本之间的相关性
  • 例如,阶数为 3 的自相关返回序列在点(t_1t_2t_3、…)与其滞后 3 个时点的值(即 t_4t_5t_6、…)之间的相关性
  • 用于发现时间序列中的重复模式或周期信号
用 Python 可视化时间序列数据

Statsmodels

statsmodels 是一个 Python 模块,提供用于估计多种统计模型的类与函数,并可进行统计检验和数据探索。

用 Python 可视化时间序列数据

绘制自相关

import matplotlib.pyplot as plt
from statsmodels.graphics import tsaplots
fig = tsaplots.plot_acf(co2_levels['co2'], lags=40)

plt.show()
用 Python 可视化时间序列数据

解读自相关图

时间序列中的自相关

用 Python 可视化时间序列数据

时间序列中的偏自相关

  • 与自相关不同,偏自相关会去除前面时点的影响
  • 例如,order 3 的偏自相关函数返回序列(t1t2t3、…)与自身滞后 3 个时点(t4t5t6、…)的相关性,但先去除了 1 阶和 2 阶滞后的全部影响
用 Python 可视化时间序列数据

绘制偏自相关

import matplotlib.pyplot as plt

from statsmodels.graphics import tsaplots
fig = tsaplots.plot_pacf(co2_levels['co2'], lags=40)

plt.show()
用 Python 可视化时间序列数据

解读偏自相关图

时间序列中的偏自相关

用 Python 可视化时间序列数据

开始练习!

用 Python 可视化时间序列数据

Preparing Video For Download...