admin管理员组文章数量:1315951
I am trying to compute the Spearman rank correlation coefficient between two ranked lists using scipy.stats.spearmanr and manually using the formula:
However, I am getting significantly different results.
I have two lists representing the top 10 similar users identified using two different methods:
Method 1 Rankings:
User ID: [301, 597, 414, 477, 57, 369, 206, 535, 590, 418]
Rank: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Method 2 Rankings:
User ID: [301, 477, 19, 120, 75, 57, 597, 160, 577, 369]
Rank: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
I then applied Spearman’s rank correlation using scipy.stats.spearmanr:
from scipy.stats import spearmanr
method1 = [301, 597, 414, 477, 57, 369, 206, 535, 590, 418]
method2 = [301, 477, 19, 120, 75, 57, 597, 160, 577, 369]
coef, _ = spearmanr(method1, method2)
print(f"Spearman coefficient: {coef}")
Spearman coefficient: 0.2727
Manual Calculation: To verify, I computed ρ manually using the common users between both lists.
User ID | Rank (Method 1) | Rank (Method 2) | (d_i = R_1 - R_2) | (d_i^2) |
---|---|---|---|---|
301 | 1 | 1 | 0 | 0 |
597 | 2 | 7 | -5 | 25 |
477 | 4 | 2 | 2 | 4 |
57 | 5 | 6 | -1 | 1 |
369 | 6 | 10 | -4 | 16 |
I am trying to compute the Spearman rank correlation coefficient between two ranked lists using scipy.stats.spearmanr and manually using the formula:
However, I am getting significantly different results.
I have two lists representing the top 10 similar users identified using two different methods:
Method 1 Rankings:
User ID: [301, 597, 414, 477, 57, 369, 206, 535, 590, 418]
Rank: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Method 2 Rankings:
User ID: [301, 477, 19, 120, 75, 57, 597, 160, 577, 369]
Rank: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
I then applied Spearman’s rank correlation using scipy.stats.spearmanr:
from scipy.stats import spearmanr
method1 = [301, 597, 414, 477, 57, 369, 206, 535, 590, 418]
method2 = [301, 477, 19, 120, 75, 57, 597, 160, 577, 369]
coef, _ = spearmanr(method1, method2)
print(f"Spearman coefficient: {coef}")
Spearman coefficient: 0.2727
Manual Calculation: To verify, I computed ρ manually using the common users between both lists.
User ID | Rank (Method 1) | Rank (Method 2) | (d_i = R_1 - R_2) | (d_i^2) |
---|---|---|---|---|
301 | 1 | 1 | 0 | 0 |
597 | 2 | 7 | -5 | 25 |
477 | 4 | 2 | 2 | 4 |
57 | 5 | 6 | -1 | 1 |
369 | 6 | 10 | -4 | 16 |
we have only 5 common users, n=5.
Using the formula I got Spearman coefficient(
本文标签: pythonSpearman Rank Correlation in SciPy vs Manual CalculationMismatch in ResultsStack Overflow
版权声明:本文标题:python - Spearman Rank Correlation in SciPy vs. Manual Calculation - Mismatch in Results - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741984834a2408613.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论