Skip to content

Instantly share code, notes, and snippets.

@trevorwhitney
Created December 4, 2011 02:29
Show Gist options
  • Select an option

  • Save trevorwhitney/1428918 to your computer and use it in GitHub Desktop.

Select an option

Save trevorwhitney/1428918 to your computer and use it in GitHub Desktop.
Jaccard similarity coefficient
def similarity
similarity = 0.0
n = 0.0
@person1.each_index do |index|
if @person1[index] == 0 && @person2[index] == 1
n += 1
elsif @person1[index] == 1 && @person2[index] == 0
n += 1
elsif @person1[index] == 1 && @person2[index] == 1
similarity += 1
end
end
n += similarity
jaccard = similarity / n
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment