0
$\begingroup$
I have input like below:

input_list = [['Search' 'engines','using','machine','learning','pattern','detections'], 

        ['machine','learning','helped','Google','automatically','sift','pages']]

input_list1 = ['Machine','learning','ever','evolving','technology']

Expecting jaccard similarity distance between input_list and input_list1

$\endgroup$
0
$\begingroup$

Since u have tokenized them, the jaccard distance is simply:

size(input_list intersect input_list1)/size(input_list union input_list1)

Reference: https://en.wikipedia.org/wiki/Jaccard_index

$\endgroup$
0
$\begingroup$
input_list = [['Search', 'engines','using','machine','learning','pattern','detections'], ['machine','learning','helped','Google','automatically','sift','pages']]
flat_list = [item for sublist in input_list for item in sublist]
input_list1 = ['Machine','learning','ever','evolving','technology']

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

jaccard_similarity(flat_list, input_list1)

Output:

0.05555555555555555
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.