Scipy:Pearson的相关性总是返回1 [英] Scipy: Pearson's correlation always returning 1

查看:58
本文介绍了Scipy:Pearson的相关性总是返回1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python库scipy计算两个浮点数组的Pearson相关性.即使数组不同,系数的返回值也始终为1.0.例如:

I am using Python library scipy to calculate Pearson's correlation for two float arrays. The returned value for coefficient is always 1.0, even if the arrays are different. For example:

[-0.65499887  2.34644428]
[-1.46049758  3.86537321]

我以这种方式调用例程:

I am calling the routine in this way:

r_row, p_value = scipy.stats.pearsonr(array1, array2)

r_row 的值始终为1.0.我在做什么错了?

The value of r_row is always 1.0. What am I doing wrong?

推荐答案

皮尔逊相关系数为衡量线性回归对数据的拟合程度的方法.如果仅提供两个点,则一条直线正好穿过两个点,因此您的数据完全适合一条直线,因此相关系数恰好为1.

Pearson's correlation coefficient is a measure of how well your data would be fitted by a linear regression. If you only provide it with two points, then there is a line passing exactly through both points, hence your data perfectly fits a line, hence the correlation coefficient is exactly 1.

这篇关于Scipy:Pearson的相关性总是返回1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆