# Jaccard similarity coefficient The [Jaccard similarity coefficient](https://en.wikipedia.org/wiki/Jaccard_index), also known as the Tanimoto Index / coefficient, is a statistic used for gauging the similarity and diversity of finite sample sets. It was developed by Grove Karl Gilbert in 1884 for the field of weather forecasting [\[1\]](https://journals.ametsoc.org/view/journals/wefo/11/1/1520-0434_1996_011_0003_tfaase_2_0_co_2.xml) and later independently developed by Paul Jaccard [\[2\]](https://doi.org/10.1111/j.1469-8137.1912.tb05611.x) who was studying species of alpine plants. Finally, it was also formulated again by T. Tanimoto [\[3\]](https://agris.fao.org/agris-search/search.do?recordID=US201300372414). Overall, it is widely used in various fields including computer science, ecology, genomics, and other sciences, where binary or binarized data are used. Mathematically speaking, it is defined as the size of the [intersection][1] divided by the size of the [union][2] of finite sample sets. Specifically, for two sets \$A\$ and \$B\$ it is defined as: \$J(A, B) = \frac{|A \bigcap B|}{|A\bigcup B|}\$ It ranges from \$0<= J(A, B) <=1\$, where `0` is the case of the intersection between \$A\$ and \$B\$ being equal to the empty set. # Challenge Given two finite sets, containing positive or negative integers, calculate their Jaccard coefficient. If your language of choice does not natively support sets, you can use an `array / vector / list` type. You may assume that at least one of the sets will be non-empty. ## Test cases {1, 2}, {} -> 0.0 {1, 2, 3}, {2, 4, 6} -> ~0.167 {-7, 3, 9}, {-9, 2, 3} -> 0.2 {0, 64}, {0, 64, 89} -> 0.5 {6, 42, 7, 1}, {42, 7, 6} -> 0.75 {3, 6, 9}, {3, 6, 9} -> 1.0 ## Rules - You may use [any standard I/O method](https://codegolf.meta.stackexchange.com/q/2447) - [Standard loopholes](https://codegolf.meta.stackexchange.com/q/1061) are forbidden - This is [tag:code-golf], so shortest answer in bytes wins. [1]: https://en.wikipedia.org/wiki/Intersection_(set_theory) [2]: https://en.wikipedia.org/wiki/Union_(set_theory)