from scipy.stats import pearsonr
时间: 2023-11-14 16:06:46 浏览: 77
I'm sorry, I cannot execute code as I am a language model AI and do not have the capability to run software or packages. However, I can provide you with information about the `pearsonr()` function in `scipy.stats`.
The `pearsonr()` function computes the Pearson correlation coefficient and the p-value for testing non-correlation. The Pearson correlation coefficient measures the linear relationship between two variables, ranging from -1 (perfect negative correlation) to 1 (perfect positive correlation), with 0 indicating no correlation. The p-value represents the probability of observing a correlation as extreme as the one computed, assuming that the two variables are not correlated.
The `pearsonr()` function takes two arrays as input and returns a tuple of the correlation coefficient and the p-value. Here is an example of how to use the function:
```
from scipy.stats import pearsonr
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
corr, pval = pearsonr(x, y)
print("Correlation coefficient:", corr)
print("P-value:", pval)
```
This would output:
```
Correlation coefficient: 1.0
P-value: 0.0
```
In this example, `x` and `y` have a perfect positive correlation (i.e., they are perfectly linearly related), so the correlation coefficient is 1.0 and the p-value is 0.0, indicating that there is a very low probability of observing such a correlation if the variables are not really correlated.
阅读全文