Skip to content

Instantly share code, notes, and snippets.

@marcelcaraciolo
Created August 21, 2012 19:12
Show Gist options
  • Save marcelcaraciolo/3418448 to your computer and use it in GitHub Desktop.
Save marcelcaraciolo/3418448 to your computer and use it in GitHub Desktop.
jaccard
def jaccard(users_in_common, total_users1, total_users2):
'''
The Jaccard Similarity between 2 two vectors
|Intersection(A, B)| / |Union(A, B)|
'''
union = total_users1 + total_users2 - users_in_common
return (users_in_common / (float(union))) if union else 0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment