简体   繁体   English

Python:两组数据之间的相关系数

[英]Python: correlation co-efficient between two sets of data

Correlation Co-efficient calculation in Python Python中的相关系数计算

How would I calculate the correlation coefficient using Python between the spring training wins column and the regular-season wins column?如何使用 Python 计算春季训练获胜列和常规赛获胜列之间的相关系数?

Name姓名 Spr.TR春风 Reg Szn注册证
Team B B组 0.429 0.429 0.586 0.586
Team C C队 0.417 0.417 0.646 0.646
Team D D组 0.569 0.569 0.6 0.6
Team E E队 0.569 0.569 0.457 0.457
Team F F队 0.533 0.533 0.563 0.563
Team G G队 0.724 0.724 0.617 0.617
Team H H组 0.5 0.5 0.64 0.64
Team I第一组 0.577 0.577 0.649 0.649
Team J J队 0.692 0.692 0.466 0.466
Team K K队 0.5 0.5 0.477 0.477
Team L L队 0.731 0.731 0.699 0.699
Team M M组 0.643 0.643 0.588 0.588
Team N N队 0.448 0.448 0.531 0.531

You can use corr (Pearson correlation by default):您可以使用corr (默认为 Pearson 相关性):

df['Spr.TR'].corr(df['Reg Szn'], method='pearson')

output: 0.10811116955657629输出: 0.10811116955657629

If we assume that your data is in a variable of type pandas.DataFrame named df.如果我们假设您的数据位于名为 df 的 pandas.DataFrame 类型的变量中。

from scipy.stats.stats import pearsonr   

correlation = pearsonr(df["Spr.TR"].tolist(),df["Reg Szn"].tolist())[0]

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

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