当我按降分数排序时,我必须计算我计算出的(name, score)
list
之间的Spearman相关性。
您可以假设没有并列等级,这意味着可以使用Spearman计算的简单形式。
我可以不使用scipy
来计算吗?我尝试使用scipy.stats
模块,但没有任何反应。我也可以使用scipy
。
import scipy.stats
x=[['x',0.212],['a', 0.324],['s', -2.432], ['b',0.2342],['x', -3.232]]
def spearman(l):
c = []
for i in l:
c.append(scipy.stats.pearsonr(i,i+1))
return c
computed_spearman = spearman(x)
我遇到以下错误:
回溯(最近一次通话最后一次):文件“”,第2行,在 TypeError:只能将列表(而不是“ int”)连接到列表
答案 0 :(得分:0)
如果要使用熊猫计算Spearman相关性,则可以按照以下步骤进行操作:
import pandas as pd
x = [['x',0.212], ['a', 0.324], ['s', -2.432], ['b',0.2342], ['x', -3.232]]
df = pd.DataFrame(data=x)
df.corr(method='spearman')
但是,我看不出这对您的数据有何意义。也许您可以澄清您的意图。