首页 文章

皮尔逊相关零值

提问于
浏览
0

我正在计算Pearson Correlation . 最后我得到了如下结果(correlation1) . 我想知道为什么我的所有第二个系数都有0.0作为相关的结果1 . 有谁能解释一下?而且,我的相关代码运行缓慢 . 我怎么能快点?

结果(样本):
(0.52543523179249552, 0.0), (0.52543905756911169, 0.0), (0.52544196572206603, 0.0), (0.52545010637443945, 0.0)...

from scipy.stats import pearsonr

s1_list = []
s2_list = []
s3_list = []
s4_list = []

zip_list1 = []
zip_list2 = []

correlation1 = []
for x, y in zip(speed1_list, speed2_list):
    zip1 = {"s1": float(x), "s2": float(y)}
    s1_list.append(zip1["s1"])
    s2_list.append(zip1["s2"])
    zip_list1.append(zip1)
    correlation1.append(pearsonr(s1_list,s2_list))

print correlation1

输入:

speed1_list: [113.0, 116.0, 120.0, 120.0, 117.0, 127.0, 124.0, 118.0, 124.0, 128.0, 128.0, 125.0, 112.0, 122.0, 125.0, 133.0, 128.0, 129.0, 126.0, 123.0, 120.0, 118.0, 114.0, 119.0, 129.0, 127.0, 128.0, 122.0, 120.0, 125.0, 119.0...]

speed2_list: [125.0, 123.0, 120.0, 115.0, 124.0, 120.0, 120.0, 119.0, 119.0, 122.0, 121.0, 116.0, 116.0, 119.0, 116.0, 113.0, 113.0, 115.0, 120.0, 122.0, 122.0, 113.0, 118.0, 121.0, 120.0, 119.0, 116.0...]

correlation1: (0.52543523179249552, 0.0), (0.52543905756911169, 0.0), (0.52544196572206603, 0.0), (0.52545010637443945, 0.0)...

1 回答

  • 0

    如果您阅读documentation of the pearsonr function,您会看到第二项是p值,表示Pearson在数据集之间的相关性等于0的概率 .

    如果我在您的示例列表上运行您的代码,我只得到一个0 p值:

    correlation1 = [(nan, nan), (-1.0, 0.0), (-0.99946642948624609, 0.020797462218684917), (-0.87259228616792028, 0.12740771383207972), (-0.82714719627765909, 0.083995277603981247), (-0.58025386521762756, 0.22730335863992135), (-0.57868746304695651, 0.17345428063365897), (-0.53247171319158504, 0.17427615080621298), ...

    但是我猜你给 correlation1 的值来自列表中的更多值,你有足够的样本来使你的相关非常精确,因此p值为0 .

相关问题