肯德尔相关系数python
时间: 2023-10-19 22:34:34 浏览: 62
Kendall's correlation coefficient is a measure of the strength and direction of association between two ranked variables. In Python, you can calculate Kendall's correlation coefficient using the `scipy` library. Here's an example:
```python
import scipy.stats as stats
# Example data
x = [1, 2, 3, 4, 5]
y = [3, 1, 2, 5, 4]
# Calculate Kendall's correlation coefficient
tau, p_value = stats.kendalltau(x, y)
# Print the result
print("Kendall's correlation coefficient:", tau)
print("p-value:", p_value)
```
Make sure you have the `scipy` library installed before running this code. The function `kendalltau()` returns Kendall's correlation coefficient (`tau`) and the corresponding p-value (`p_value`).