繁体   English   中英

如何在scipy中使用pearsonr函数查找字典值的相关性和P值?

[英]How do I use the pearsonr function in scipy to find the correlation and P-Value of dictionary values?

我在下面有一些Python代码:

a = dict.values(histodict[str(start)])
b = dict.values(histodict[str(end)])
print pearsonr(a,b)

指示脚本执行操作时,变量a和b都将正确显示为列表,但是它们不会在scipy中的pearsonr函数中响应。

我想知道为什么这不起作用。 返回的错误是:

Traceback (most recent call last):
File "BlackBox.py", line 32, in <module>
print corr(a,b)
File "/usr/lib/python2.6/dist-packages/scipy/stats/stats.py", line 1596, in pearsonr
mx = x.mean()
TypeError: cannot perform reduce with flexible type

并且由于此代码目前的形式显然不起作用,如何在scipy中使用pearsonr函数返回字典值的相关性和P值?

根据您的评论,您的值不是整数/浮点数:

a = [float(x) for x in histodict[str(start)].itervalues()]
b = [float(x) for x in histodict[str(end)].itervalues()]
print pearsonr(a,b)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM