自相关函数和偏自相关函数(ACF、PACF)

前言

简单介绍一下自相关函数ACF和偏自相关函数 PACF的计算和图像显示,概念性的东西可以查阅其他资料了解。

实例

  • 数值计算
import statsmodels.tsa.api as smt

time_series = [1,2,3,4,5,6,7,8]
acf = smt.stattools.acf(time_series)
pacf = smt.stattools.pacf(time_series,nlags = 3)
print(acf)
print(pacf)

结果展示

[ 1.          0.625       0.27380952 -0.0297619  -0.26190476 -0.39880952
 -0.41666667 -0.29166667]
[ 1.          0.71428571 -0.2962963  -0.38947368]
  • 图像
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
import matplotlib.pyplot as plt
import numpy as np

plot_acf(np.array(time_series))

plt.tight_layout()
plt.show()

《自相关函数和偏自相关函数(ACF、PACF)》

from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
import matplotlib.pyplot as plt
import numpy as np

plot_pacf(np.array(time_series),lags=3)

plt.tight_layout()
plt.show()

《自相关函数和偏自相关函数(ACF、PACF)》

总结

  • ACF 和 PACF 在AR 、MA 和ARMA模型中举重若轻
  • 截尾:在大于某个常数k后快速趋于0为k阶截尾
  • 拖尾:始终有非零取值,不会在k大于某个常数后就恒等于零(或在0附近随机波动)
    原文作者:nsq1101
    原文地址: https://blog.csdn.net/weixin_45063703/article/details/120687581
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞