Jaccard相似度得分ValueError:Python不支持多类多输出

时间:2018-03-19 10:32:54

标签: python list set similarity neighbours

我想计算两个列表或单词集的jaccard索引。 我的价值观如下:

list1: [('Golden', 0.35036513209342957), ('waking', 0.3429567813873291), ('Keep', 0.34041523933410645), ('Lying', 0.33063751459121704), ('washed', 0.3259369730949402), ('wedged', 0.32253023982048035), ('enjoyment', 0.32023900747299194), ('mid-December', 0.31836390495300293), ('whispered', 0.3126818835735321), ('jittery', 0.31083038449287415)]

如果我计算jaccard_similarity_score(list1,list2),我会收到此错误ValueError: multiclass-multioutput is not supported

我还尝试使用这样的集合:

set1=set()
set2=set()

for el in list1:
    set1.add(el[0])
for el in list2:
    set2.add(el[0])
j=jaccard_similarity_score(set1,set2)

但我收到此错误ValueError: Expected array-like (array or non-string sequence), got set(['whispered', 'Golden', 'enjoyment', 'washed', 'wedged', 'Keep', 'mid-December', 'jittery', 'waking', 'Lying']) 我做错了什么?

1 个答案:

答案 0 :(得分:0)

docs看来你需要这个:

l1 = [i[0] for i in list1]
l2 = [j[0] for j in list2]
j = jaccard_similarity_score(l1,l2)