两个数据列表的相关性 [英] correlation for two lists of data
本文介绍了两个数据列表的相关性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这两个列表包含如下数据:
These two lists contain data something like this:
a = [1 2 1 3 1 2 1 1 1 2 1 1 2 1 4 1 ]
b = [ 3480. 7080. 10440. 13200. 16800. 20400. 23880. 27480. 30840. 38040. 41520. 44880. 48480. 52080. 55680. 59280.]
如何通过导入 rpy2
使用python查找关联,我的意思是 cor
函数。并且o / p必须介于-1和+1之间。
How to find correlation using python by importing rpy2
, I mean cor
function. And the o/p has to lie between -1 and +1.
推荐答案
from rpy2.robjects.vectors import FloatVector
from rpy2.robjects.packages import importr
stats = importr('stats')
a=[1, 2, 1, 3, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 4, 1 ]
b=[ 3480, 7080, 10440, 13200, 16800, 20400, 23880,
27480, 30840, 38040, 41520, 44880, 48480, 52080, 55680, 59280]
result = stats.cor(FloatVector(a), FloatVector(b))
rpy2的文档还提供了许多其他有关如何使用它的示例。
The documentation for rpy2 has many other examples about how to use it.
这篇关于两个数据列表的相关性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文