python - 在 Python 中计算 Pearson 相关性和显着性

我正在寻找一个将两个列表作为输入并返回 Pearson correlation 的函数。 ,以及相关性的重要性。

最佳答案

你可以看看scipy.stats :

from pydoc import help
from scipy.stats.stats import pearsonr
help(pearsonr)

>>>
Help on function pearsonr in module scipy.stats.stats:

pearsonr(x, y)
 Calculates a Pearson correlation coefficient and the p-value for testing
 non-correlation.

 The Pearson correlation coefficient measures the linear relationship
 between two datasets. Strictly speaking, Pearson's correlation requires
 that each dataset be normally distributed. Like other correlation
 coefficients, this one varies between -1 and +1 with 0 implying no
 correlation. Correlations of -1 or +1 imply an exact linear
 relationship. Positive correlations imply that as x increases, so does
 y. Negative correlations imply that as x increases, y decreases.

 The p-value roughly indicates the probability of an uncorrelated system
 producing datasets that have a Pearson correlation at least as extreme
 as the one computed from these datasets. The p-values are not entirely
 reliable but are probably reasonable for datasets larger than 500 or so.

 Parameters
 ----------
 x : 1D array
 y : 1D array the same length as x

 Returns
 -------
 (Pearson's correlation coefficient,
  2-tailed p-value)

 References
 ----------
 http://www.statsoft.com/textbook/glosp.html#Pearson%20Correlation

https://stackoverflow.com/questions/3949226/

相关文章:

linux - 在一行中从 linux 终端发送邮件

linux - 什么是不间断进程?

python - 使用 Python 处理 csv 文件时如何跳过标题?

Python 函数属性 - 使用和滥用

Linux - 仅安装 redis-cli

linux - 如何阅读 shell 命令的源代码?

python - 在 Python 中创建具有初始容量的列表

mysql - 无法连接到 MySQL 服务器错误 111

linux - 单击选项卡时出现shell init问题,getcwd有什么问题?

python - Python中的退出代码