我使用autocorrelation_plot绘制了一条直线的自相关:
import numpy as np
import pandas as pd
from pandas.plotting import autocorrelation_plot
import matplotlib.pyplot as plt
dr = pd.date_range(start='1984-01-01', end='1984-12-31')
df = pd.DataFrame(np.arange(len(dr)), index=dr, columns=["Values"])
autocorrelation_plot(df)
plt.show()

然后,我尝试使用autocorr()来计算具有不同滞后的自相关:
for i in range(0,366):
print(df['Values'].autocorr(lag=i))对于所有延迟,输出为1(或0.99)。但从相关图中可以清楚地看出,自相关是一条曲线,而不是一条固定在1的直线。
我是不是错误地解释了correlogram,还是错误地使用了autocorr()函数?谢谢!
发布于 2019-01-03 20:43:05
您正确地使用了这两个函数,但是...与autocorr()相比,Autocorrelation_plot使用不同的方法来计算自相关性。
下面两篇文章解释了更多的不同之处。不幸的是,我不知道哪种计算方法是正确的:
What's the difference between pandas ACF and statsmodel ACF?
如果需要,您可以从自相关图中获得自相关,如下所示:
ax = autocorrelation_plot(df)
ax.lines[5].get_data()[1]https://stackoverflow.com/questions/54017871
复制相似问题