The above examples show that there are two ways for you to access the values:
The .at accesses a single value by row and column labels.
The .iat accesses a value based on its row and column positions.
Rank correlation compares the orderings or the ranks of the data related to two features or variables of a dataset.
If the orderings are found to be similar, then the correlation is said to be strong, positive, and high.
On the other hand, if the orderings are found to be close to reversed, the correlation is said to be strong, negative, and low.
Spearman Correlation Coefficient
This is the Pearson correlation coefficient between the rank values of two features.
It’s calculated just as the Pearson correlation coefficient but it uses the ranks instead of their values.
It’s denoted using the Greek letter rho (ρ), the Spearman’s rho.
Here are important points to note concerning the Spearman correlation coefficient:
The ρ can take a value in the range of −1 ≤ ρ ≤ 1.
The maximum value of ρ is 1, and it corresponds to a case where there is a monotonically increasing function between x and y. Larger values of x correspond to larger values of y. The vice versa is also true.
The minimum value of ρ is -1, and it corresponds to a case where there is a monotonically decreasing function between x and y. Larger values of x correspond to smaller values of y. The vice versa is also true.
Kendall Correlation Coefficient
Let’s consider two n-tuples again, x and y.
Each x-y, pair, (x1, y1)…, denotes a single observation.
Each pair of observations, (xᵢ, yᵢ), and (xⱼ, yⱼ), where i < j, will be one of the following:
concordant if (xᵢ > xⱼ and yᵢ > yⱼ) or (xᵢ < xⱼ and yᵢ < yⱼ)
discordant if (xᵢ < xⱼ and yᵢ > yⱼ) or (xᵢ > xⱼ and yᵢ < yⱼ)
neither if a tie exists in either x(xᵢ = xⱼ) or in y(yᵢ = yⱼ)
The Kendall correlation coefficient helps us compare the number of concordant and discordant data pairs.
The coefficient shows the difference in the counts of concordant and discordant pairs in relation to the number of x-y pairs.
Note the following points concerning the Kendall correlation coefficient:
It takes a real value in the range of −1 ≤ τ ≤ 1.
It has a maximum value of τ = 1 which corresponds to a case when all pairs are concordant.
It has a minimum value of τ = −1 which corresponds to a case when all pairs are discordant.
SciPy Implementation of Rank
The scipy.stats can help you determine the rank of each value in an array.
Let’s first import the libraries and create NumPy arrays: