Search code examples
pythonlistsetsimilarityneighbours

Jaccard similarity score ValueError: multiclass-multioutput is not supported Python


I want to calculate the jaccard index of two lists or sets of words. I have values as follow:

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)]

If I compute jaccard_similarity_score(list1,list2) I get this error ValueError: multiclass-multioutput is not supported.

I tried also to use sets like that:

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)

but I get this error ValueError: Expected array-like (array or non-string sequence), got set(['whispered', 'Golden', 'enjoyment', 'washed', 'wedged', 'Keep', 'mid-December', 'jittery', 'waking', 'Lying']) What am I doing wrong?


Solution

  • From the docs it seems you need this:

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