Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CoNekT/utils/jaccard.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
14 lines (10 sloc)
350 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def jaccard(list_a, list_b): | |
""" | |
Calculates the jaccard index from two python lists. | |
:param list_a: First list | |
:param list_b: Other list | |
:return: The jaccard index | |
""" | |
union_count = len(set(list_a + list_b)) | |
intersection_count = len(set(list_a).intersection(set(list_b))) | |
return intersection_count/union_count |