小编Ett*_*ana的帖子

numpy和statsmodels在计算相关性时会给出不同的值,如何解释?

我找不到为什么计算两个系列A和B之间的相关性numpy.correlate给出的结果与我得到的结果不同的原因statsmodels.tsa.stattools.ccf

以下是我提到的这种差异的一个例子:

import numpy as np
from matplotlib import pyplot as plt
from statsmodels.tsa.stattools import ccf

#Calculate correlation using numpy.correlate
def corr(x,y):
    result = numpy.correlate(x, y, mode='full')
    return result[result.size/2:]

#This are the data series I want to analyze
A = np.array([np.absolute(x) for x in np.arange(-1,1.1,0.1)])
B = np.array([x for x in np.arange(-1,1.1,0.1)])

#Using numpy i get this
plt.plot(corr(B,A))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

#Using statsmodels i get this
plt.plot(ccf(B,A,unbiased=False))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

结果看起来质量上有所不同,这种差异来自哪里?

python numpy cross-correlation statsmodels

5
推荐指数
1
解决办法
1953
查看次数

标签 统计

cross-correlation ×1

numpy ×1

python ×1

statsmodels ×1