【发布时间】:2019-09-25 11:05:59
【问题描述】:
在 python (+ pandas/numpy/scipy/statsmodels) 中是否有返回自相关 wrt lag 的函数?这样的东西是否存在现成的库函数?
为避免混淆,我想要以下内容,只是我不想绘制它,但我希望它作为一个系列(pd.Series 或 pd.DataFrame)返回:
import numpy as np
import pandas as pd
from statsmodels.graphics.tsaplots import plot_acf
from matplotlib import pyplot as plt
plt.ion()
s = pd.Series(np.sin(range(1,100))) + pd.Series(np.random.randn(99))
plot_acf(s)
实际上,我想要 pd.Series.autocorr() 返回的内容,但我想要一个系列而不是一个标量,其中系列包含各种滞后的自相关。
编辑:
实现上述目的的一种方法是:
pd.Series([s.autocorr(i) for i in range(0,s.shape[0]-1)], index=range(0,s.shape[0]-1))
【问题讨论】:
-
@Wen-Ben 它只显示如何绘制 acf/pacf。看不到任何返回 acf/pacf 系列的代码。
-
stackoverflow.com/questions/14297012/… sry 只是复制错误的页面
-
@Wen-Ben 我的意思是我可以使用 pd.Series.autocorr() tbh 的列表理解,只是认为有更复杂的东西。好的,我自己写函数。
-
我提供了一种方法,希望它比你的旧线路更快
标签: python pandas statistics signal-processing statsmodels