Skip to content

Instantly share code, notes, and snippets.

@andrewluetgers
Created January 21, 2015 06:52
Show Gist options
  • Save andrewluetgers/55174d0886c79c3d0696 to your computer and use it in GitHub Desktop.
Save andrewluetgers/55174d0886c79c3d0696 to your computer and use it in GitHub Desktop.
function jaccardIndex(s1, s2) {
// Jaccard index: http://en.wikipedia.org/wiki/Jaccard_index
// size of the intersection divided by the size of the union of the sample sets
s1 = _.isArray(s1) ? s1 : _.keys(s1);
s2 = _.isArray(s2) ? s2 : _.keys(s2);
return _.intersection(s1, s2).length / _.union(s1, s2).length
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment