Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the relationship between pearson, spearman and kendall

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly talks about "what is the relationship between pearson, spearman and kendall". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the relationship between pearson, spearman and kendall".

The three major correlation coefficients in statistics: pearson, spearman, kendall, they all reflect the direction and degree of the trend between the two variables, with values ranging from-1 to + 1. 0 indicates that the two variables are not related, positive values indicate positive correlation, negative values indicate negative correlation, and the higher the value, the stronger the correlation. 1. Person correlation coefficient (Pearson correlation coefficient) Pearson correlation coefficient is usually expressed as r or ρ to measure the relationship between two variables X and Y (linear correlation). (1) the value of Pearson correlation coefficient is equal to their covariance cov (XQuery Y) divided by the product of their respective standard deviations (σ X, σ Y). (2) data requirements a. Normal distribution is the ratio of covariance to standard deviation, and after calculating Pearson correlation coefficient, we usually use methods such as t-test to test Pearson correlation coefficient, and t-test is based on the assumption that the data are normally distributed. b. The gap between the experimental data should not be too large, for example, to study the correlation between running speed and heartbeat, if a person has a heart attack and the heartbeat is 0 (or too fast or too slow), then we will measure a heartbeat that deviates from the normal value. if we put this value into the correlation analysis, its existence will greatly interfere with the results of the calculation. (3) instance code

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

Import pandas as pd

Import numpy as np

# Raw data

X1=pd.Series ([1,2,3,4,5,6])

Y1=pd.Series ([0.3,0.9,2.7,2,3.5,5])

X1.mean () # average # 3.5

Y1.mean () # 2.4

X1.var () # Variance # 3.5

Y1.var () # 2.9760000000000004

X1.std () # standard deviation cannot be "1.8708286933869707"

Y1.std () # standard deviation cannot be 01.725108692227826

X1.cov (Y1) # covariance # 3.06000000000005

X1.corr (Y1 method = "pearson") # Pearson correlation coefficient # 0.948136664010285

X1.cov (Y1) / (X1.std () * Y1.std ()) # Pearson correlation coefficient # 0.948136664010285

Spelman correlation coefficient, also known as Spelman rank correlation coefficient. " Rank ", it can be understood that achievement is a kind of order or sort, then it is solved according to the sorting position of the original data. First, sort the data of two variables (X, Y), then write down the position after sorting (X, Y, Y'). The value of (X, Y) is called rank, and the difference of rank is the di,n in the above formula is the number of data in the variable. Finally, the result can be solved by introducing the formula. Because it is a sequence, we do not care about the difference between the specific values of X and Y, we only need to calculate the difference in the arrangement position of each of their values, and then we can find out the correlation coefficient.

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

twenty-three

Import pandas as pd

Import numpy as np

# Raw data

X1=pd.Series ([1,2,3,4,5,6])

Y1=pd.Series ([0.3,0.9,2.7,2,3.5,5])

# processing data to delete Nan

X1=X1.dropna ()

Y1=Y1.dropna ()

N=x1.count ()

X1.index=np.arange (n)

Y1.index=np.arange (n)

# partial calculation

D = (x1.sort_values () .index-y1.sort_values () .index) * * 2

Dd=d.to_series () .sum ()

P=1-n*dd/ (n * (n = 1))

# calculation of s.corr () function

R=x1.corr (y1methodological spearman')

Print (RJournal p) # 0.942857142857143 0.9428571428571428

3. Kendall correlation coefficient (Kendall correlation coefficient)

Kendall correlation coefficient, also known as Kendall rank correlation coefficient, is also a kind of rank correlation coefficient, but the object it calculates is classification variables. Classified variables can be understood as classified variables, which can be divided into: (1) disordered, such as gender (male, female), blood type (A, B, O, AB); (2) ordered, such as obesity grade (severe obesity, moderate obesity, mild obesity, non-obesity). Usually, it is the ordered classification variables that require the correlation coefficient. R = (P-(n * (n ~ *) / 2)) / (n * (n ~ *) / 2) = (4P/ (n * (n ~ *)-1 Note: there are n statistical objects, each of which has two attributes. All statistical objects are arranged according to the value of attribute 1 without losing generality. at this time, the arrangement of the values of attribute 2 is out of order. Let P be the logarithmic category data of two statistical objects with the same arrangement of attribute values or data that can be classified.

one

two

three

four

five

six

seven

Import pandas as pd

Import numpy as np

# Raw data

X = pd.Series ([3, 1, 2, 2, 2, 1, 3])

Y = pd.Series ([1, 2, 3, 2, 1, 1])

R = x.corr (y method = "kendall") #-0.2611165

At this point, I believe you have a deeper understanding of "what is the relationship between pearson, spearman and kendall". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report