Jaccard Index Calculator (Set Similarity, Tanimoto)

Jaccard index J(A,B) = |A∩B|/|A∪B| calculator: sets, binary vectors, n-grams, weighted Jaccard, comparison Sorensen-Dice, NLP/CV applications and IoU.

Calculation parameters
Was this calculator useful?

Jaccard index

Jaccard index, also Tanimoto coefficient, measures similarity between two sets A and B as ratio of intersection to union cardinalities:

J(A, B) = |A ∩ B| / |A ∪ B|

Range: [0, 1]. J = 0 if A, B disjoint, J = 1 if A = B. Introduced by Paul Jaccard (1901) for biogeographic similarity between alpine flora regions. Now standard in NLP, bioinformatics, recommender systems, CV.

Definition and formula

  • |A ∩ B| = number of common elements.
  • |A ∪ B| = total distinct elements.
  • J(A, B) = |A ∩ B| / |A ∪ B|.
  • Jaccard distance: d_J = 1 - J(A, B), range [0, 1].

Example: A = {a, b, c, d}, B = {c, d, e, f}. A ∩ B = {c, d}, A ∪ B = {a, b, c, d, e, f}. J = 2/6 = 0.333.

Binary version (Tanimoto)

For binary vectors (0/1) of length n, with n_11, n_10, n_01, n_00 counts:

J = n_11 / (n_11 + n_10 + n_01)

Excludes n_00 (both 0). Important for sparse data: two users not interacting with same product are NOT similar. Also called Tanimoto coefficient.

Sorensen-Dice coefficient

Popular variant: D(A, B) = 2 |A ∩ B| / (|A| + |B|). Range [0, 1].

  • Jaccard: |A ∩ B| / |A ∪ B|.
  • Sorensen-Dice: 2 |A ∩ B| / (|A| + |B|).
  • Relation: D = 2J / (1 + J).
  • Dice gives more weight to intersection.

Jaccard distance as metric

d_J = 1 - J(A, B) IS genuine metric (Levandowsky-Winter 1971): satisfies positivity, identity, symmetry, triangle. Note: Sorensen-Dice 1 - D NOT metric. Jaccard preferred when metric structure needed.

Example: document comparison

Tokenized texts as word sets. Documents with same key terms have high J, regardless of frequency. n-gram variant: sets of length-n substrings.

Weighted Jaccard (Ruzicka)

For non-negative integer vectors:

J_w(a, b) = sum min(a_i, b_i) / sum max(a_i, b_i)

Generalization to vectors. With binary values, recovers binary Jaccard. Used in ecology, NLP frequencies, CV histograms.

Applications

  • NLP: document similarity via token or n-gram overlap.
  • Recommender systems: similar users via product sets.
  • Bioinformatics: genome similarity, biodiversity.
  • CV: bounding box IoU - Intersection over Union.
  • Plagiarism detection: shingle-based (Broder 1997).
  • Network analysis: node similarity via shared neighbors.
  • Cheminformatics: molecule fingerprint similarity.
  • Market basket analysis.

IoU in computer vision

Intersection over Union: Jaccard for bounding boxes in object detection. IoU = Area(box_pred ∩ box_true) / Area(box_pred ∪ box_true). Standard threshold IoU >= 0.5 for true positive. COCO, ImageNet, Pascal VOC standard. Drives YOLO, Faster R-CNN losses.

MinHash and LSH

For huge sets, MinHash (Broder 1997): random hash permutation, take min hash as signature. Pr[h_min(A) = h_min(B)] = J(A, B). Estimates Jaccard in O(k) instead of O(|A| + |B|). LSH groups similar sets sub-linearly. Big data standard: Web duplicate detection, near-duplicate documents.

Limits

  • Sensitive to granularity (n-gram size, tokenization).
  • Doesn't consider order or frequency (basic version).
  • Sparse: dominated by rare terms.
  • Dense: dominated by common terms.
  • Weighted Ruzicka: not metric in general.

History

Paul Jaccard (1901): introduces index for alpine flora distribution. Tanimoto (1957): cheminformatics redefinition. Sorensen (1948), Dice (1945): ratio variant. Levandowsky-Winter (1971): prove triangle of d_J. Broder (1997): MinHash for Web. Recommender systems 90s-2000s.

Botanical origins: Paul Jaccard and biodiversity

The Jaccard index was born not in computer science but in botany. In 1901 the Swiss botanist Paul Jaccard, studying the flora of the Alps, sought a way to quantify how much two regions shared the same plant species. He thus introduced the ratio between the number of common species and the total number of species present in at least one of the two areas, giving rise to one of the longest-lived and most used similarity measures in science.

In ecology the index is still fundamental for measuring beta-diversity, that is, the turnover of species between different habitats: a high value indicates similar communities, a low one very different communities. The same idea has extended to modern genomics, where sets of expressed genes or microbial species in different samples are compared. Comparing the gut microbiome composition of two individuals, for example, reduces to computing how much their sets of bacteria overlap, exactly as Jaccard did with alpine flowers over a century ago.

Why the Jaccard distance is a true metric

Unlike the cosine distance, which does not satisfy the triangle inequality, the Jaccard distance, defined as 1 minus the Jaccard index, is a genuine metric: it respects positivity, symmetry and the triangle inequality. This means it behaves like a true geometric distance, in which the direct path between two sets is never longer than one passing through a third set. It is a valuable property, because it guarantees consistency in clustering and nearest-neighbour search algorithms.

The proof has an elegant link with probability and the MinHash technique: the Jaccard index between two sets is exactly the probability that a random permutation of their elements assigns the same minimum to both. This probabilistic interpretation not only makes the distance a metric, but allows it to be estimated quickly on huge sets without comparing them element by element, the principle behind deduplicating billions of web pages and near-duplicate detection at massive scale.

Updated July 2026

Frequently Asked Questions

What is the Jaccard index?

It is a measure of similarity between two sets, defined as the ratio of the size of their intersection to the size of their union: J(A,B) = |A intersect B| / |A union B|. It ranges from 0 (no common element) to 1 (identical sets).

How is it computed?

You count the elements common to the two sets (intersection) and the elements present in at least one of the two (union), then divide the first by the second. For example, for A = {1,2,3} and B = {2,3,4}: intersection {2,3} = 2, union {1,2,3,4} = 4, so J = 2/4 = 0.5.

What is the difference from the Dice coefficient?

The Sorensen-Dice coefficient uses 2 times the intersection divided by the sum of the sizes: 2|A intersect B|/(|A|+|B|). It gives more weight to common elements and is always greater than or equal to Jaccard. The two are related and used in similar contexts, such as comparing texts and images.

Is the Jaccard distance a metric?

Yes: the Jaccard distance, equal to 1 minus the index, satisfies positivity, symmetry and the triangle inequality, unlike the cosine distance. This property makes it reliable in clustering and nearest-neighbour search algorithms, where a true notion of distance is needed.

What is the binary or Tanimoto version?

It applies the Jaccard index to binary vectors, counting the positions where both are 1 (intersection) and those where at least one is 1 (union), excluding the double-zero positions. It is used in chemoinformatics and bioinformatics to compare molecular fingerprints.

What is weighted Jaccard?

It is a generalization to vectors with non-negative integer or real values, also called Ruzicka similarity: sum of the component-wise minima divided by the sum of the maxima. It reduces to the classical Jaccard for 0-1 vectors and is used when elements have frequencies or weights.

Who invented the Jaccard index?

The Swiss botanist Paul Jaccard in 1901, studying the flora of the Alps to measure how much two regions shared the same plant species. Since then it has become a standard measure in ecology, genomics, computer science and every field where sets need to be compared.

What is it used for in practice?

It compares documents via common words or n-grams, detects plagiarism and near-duplicates (with MinHash at web scale), measures biodiversity in ecology, evaluates the overlap of boxes in computer vision (IoU) and powers recommender systems based on sets of preferences.

Comments (0)

No comments yet. Be the first!