Calculate a similarity index (Dice/Sørensen or Jaccard) from two set sizes and the items they share, or compare two lists of items directly.

Optional settings


Related Calculators

Calculator Functions

FunctionWhat it doesWhat it requires
Dice (Sørensen) similarityFinds the Dice coefficient of two setsRequires the size of set A, the size of set B and the number of items in common
Dice → common sizeFinds the number of shared items that gives a chosen Dice coefficientRequires both set sizes and the coefficient
Dice → set A sizeFinds the size of set A that gives a chosen Dice coefficientRequires the size of set B, the items in common and the coefficient
Dice → set B sizeFinds the size of set B that gives a chosen Dice coefficientRequires the size of set A, the items in common and the coefficient
Jaccard similarityFinds the Jaccard index of two setsRequires the size of set A, the size of set B and the number of items in common
Jaccard → common sizeFinds the number of shared items that gives a chosen Jaccard indexRequires both set sizes and the index
Jaccard → set A sizeFinds the size of set A that gives a chosen Jaccard indexRequires the size of set B, the items in common and the index
Jaccard → set B sizeFinds the size of set B that gives a chosen Jaccard indexRequires the size of set A, the items in common and the index
Dice → JaccardConverts a Dice coefficient to the Jaccard index of the same two setsRequires the Dice coefficient
Jaccard → DiceConverts a Jaccard index to the Dice coefficient of the same two setsRequires the Jaccard index
Compare item listsCounts the items two pasted lists share and scores their similarityRequires list A and list B; delimiter, letter case, trimming and duplicate handling can be changed
Confusion matrix metricsFinds F1 score, IoU, precision, recall, specificity and accuracy for a binary classifierRequires true positives, false positives, false negatives and true negatives

Every set function shows the Dice coefficient, the Jaccard index and the overlap coefficient together, each on a scale from 0 to 1. Results are rounded to 4 decimal places unless another setting from 2 to 6 is chosen. When both sets are empty the similarity is undefined and the calculator says so.

Similarity Index Formulas

D = 2C ÷ (A + B) [1]
DDice (Sørensen) similarity, from 0 to 1
CNumber of items the two sets have in common
ANumber of items in set A
BNumber of items in set B

Dice (Sørensen) similarity

Sets of 30 and 25 items with 15 in common have D = 2 × 15 ÷ (30 + 25) = 0.5455. Two identical sets score 1 and two sets with nothing in common score 0. Alongside it the calculator shows the overlap coefficient, C ÷ the smaller of A and B, here 15 ÷ 25 = 0.6.

Dice → common size

C = D × (A + B) ÷ 2

For sets of 30 and 25 to reach a Dice coefficient of 0.6 they must share 16.5 items. A fractional answer is the size the coefficient implies, not a count of whole items.

Dice → set A size

A = 2C ÷ D − B

With 15 items in common, a set B of 25 and a target of 0.6, set A must hold 25 items.

Dice → set B size

B = 2C ÷ D − A

With 15 items in common, a set A of 30 and a target of 0.6, set B must hold 20 items. A coefficient of 0 is rejected in both size functions, because it leaves the size undetermined.

Jaccard similarity

J = C ÷ (A + B − C) [1]

The Jaccard index divides the shared items by the union of the two sets. The same 30, 25 and 15 give J = 15 ÷ 40 = 0.375. In image segmentation the same ratio is called intersection over union, or IoU.

Jaccard → common size

C = J × (A + B) ÷ (1 + J)

Sets of 30 and 25 need 15 items in common to reach a Jaccard index of 0.375.

Jaccard → set A size

A = C ÷ J − B + C

With 15 shared items, 25 in set B and an index of 0.375, set A holds 30 items.

Jaccard → set B size

B = C ÷ J − A + C

With 15 shared items, 30 in set A and an index of 0.375, set B holds 25 items.

Dice → Jaccard

J = D ÷ (2 − D) [1]

A Dice coefficient of 0.6 is a Jaccard index of 0.4286. Except at 0 and 1, where they agree, the two measures give different numbers for the same pair of sets [1].

Jaccard → Dice

D = 2J ÷ (1 + J) [1]

A Jaccard index of 0.375 is a Dice coefficient of 0.5455, the pair of values from the first example.

Compare item lists

Each list is split on commas, new lines or spaces, and A, B and C are counted from the items. By default letter case is ignored, surrounding spaces are trimmed and repeated items count once. The lists “apple, pear, plum, fig” and “Pear, fig, kiwi” share 2 items out of 4 and 3, giving a Dice coefficient of 0.5714 and a Jaccard index of 0.4. With duplicates counted, an item that appears twice in one list and once in the other adds 1 to the shared count.

Confusion matrix metrics

F1 = 2TP ÷
(2TP + FP + FN) [1]
IoU = TP ÷
(TP + FP + FN)

For a yes-or-no classifier the F1 score is the Dice coefficient of the predicted and the actual positives, and IoU is their Jaccard index [1]. Precision is TP ÷ (TP + FP), recall is TP ÷ (TP + FN) and specificity is TN ÷ (TN + FP) [1]. Accuracy is (TP + TN) ÷ all cases, and balanced accuracy is the mean of recall and specificity. With TP = 40, FP = 10, FN = 20 and TN = 30, F1 = 0.7273, IoU = 0.5714, precision = 0.8, recall = 0.6667, specificity = 0.75, accuracy = 0.7 and balanced accuracy = 0.7083.

Limits of This Estimate

  • The Dice coefficient and the Jaccard index always rank pairs of sets in the same order, so reporting both adds no information [1]. Pick one and name it, because 0.6 on one scale is 0.43 on the other.
  • No score counts as high or low in general. What is a good match depends on the field and on how the sets were built.
  • The number of items in common cannot be larger than either set, and both sets must be counted from the same universe of possible items.
  • List comparison matches items by exact text after the chosen case and trimming rules. Misspellings and synonyms count as different items.

Sources