如何使用 scipy 中的 pearsonr 函数查找字典值的相关性和 P 值?
我在下面有一些 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 值?
I have some Python code below:
a = dict.values(histodict[str(start)])
b = dict.values(histodict[str(end)])
print pearsonr(a,b)
Both variables a and b will print properly as a list when the script is instructed to do so but they will not respond in the pearsonr function in scipy.
I am wondering why this doesn't work. The error returned is:
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
And since this code in its current form will obviously not work, how do I use the pearsonr function in scipy to return the correlation and P-value of dictionary values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的评论,您的值不是整数/浮点数:
From your comment your values are not integers / floats: