2017-10-27 3 views

답변

1

나는 결국 내 자신의 솔루션을 작성 결국 :

def jaccard_distance(list1, list2): 
    intersection = len(list(set(list1).intersection(list2))) 
    print(list(set(list1).intersection(list2))) 
    union = (len(list1) + len(list2)) - intersection 
    return float(intersection/union) 
1

귀하의 사용자 이름이 반복되지 않는 가정하면, 당신은 같은 생각 사용할 수 있습니다

def jaccard(a, b): 
    c = a.intersection(b) 
    return float(len(c))/(len(a) + len(b) - len(c)) 

list1 = ['dog', 'cat', 'rat'] 
list2 = ['dog', 'cat', 'mouse'] 
# The intersection is ['dog', 'cat'] 
# union is ['dog', 'cat', 'rat', 'mouse] 
words1 = set(list1) 
words2 = set(list2) 
jaccard(words1, words2) 
>>> 0.5 
관련 문제