title: Implementation of Jaccard Distance metric in nltk.metrics.distance not consistent with the mathematical definition?
body: <p>I was trying to complete an NLP assignment using the Jaccard Distance metric function <code>jaccard_distance()</code> built into <code>nltk.metrics.distance</code>, when I noticed that the results from it did not make sense in the context I would expect.</p>
  
  <p>When I examined the implementation of <code>jaccard_distance()</code> in the <a href="http://www.nltk.org/_modules/nltk/metrics/distance.html#jaccard_distance" rel="nofollow noreferrer">online source</a>, I noticed that it was not consistent with the <a href="https://en.wikipedia.org/wiki/Jaccard_index" rel="nofollow noreferrer">mathematical definition</a> for the Jaccard index.</p>
  
  <p>Specifically, the implementation in <code>nltk</code> is:</p>
  
  <pre><code>return (len(label1.union(label2)) - len(label1.intersection(label2)))/len(label1.union(label2))
  </code></pre>
  
  <p>but according to the definition, the numerator term should only involve an intersection of the two sets, which means the correct implementation should be:</p>
  
  <pre><code>return len(label1.intersection(label2))/len(label1.union(label2))
  </code></pre>
  
  <p>when I wrote my own function using the latter, I indeed obtained correct answers to my assignment. For example, I was tasked to recommend a correct spelling suggestion for the misspelled word <strong>cormulent</strong>, from a comprehensive corpus of words (built in <code>nltk</code>), using Jaccard Distance on trigrams of the words. </p>
  
  <p>When I used the <code>jaccard_distance()</code> from <code>nltk</code>, I instead obtained so many perfect matches (the result from the distance function was <code>1.0</code>) that just were nowhere near being correct.</p>
  
  <p>When I used my own function the latter implementation, I was able to get a spelling recommendation of <strong>corpulent</strong>, at a Jaccard Distance of 0.4 from <strong>cormulent</strong>, a decent recommendation.</p>
  
  <p>Could there be a bug with <code>jaccard_distance()</code> in <code>nltk</code>?</p>