Dice Coefficient Calculator
Sets and similarity
- Inputs: set A holds 120 elements, set B holds 100 and the intersection holds 80.
- Union: 120 + 100 - 80 = 140 elements.
- Shared weight: 2 x 80 / (120 + 100) = 0.727.
- Dice coefficient result: 0.727 - a Jaccard index of 0.571 on the same sets.
How similar are two sets? The Dice coefficient - proposed by Lee Dice in 1945 for comparing ecological communities and published independently by Thorvald Sorensen in 1948 - answers with a ratio built for the question: twice the size of the intersection, divided by the sum of the two set sizes. Identical sets score 1, disjoint sets score 0, and everything real lives in between. The double counting of the overlap is the design's signature: shared elements are weighted against both sets at once, which makes Dice systematically more generous than its cousin the Jaccard index.
Enter the two set sizes and the size of their intersection. The page returns the Dice coefficient, the Jaccard index for the same pair, the union size and the overlap coefficient. The examples compare a strongly overlapping pair, a modest one, and two large sets with a deep common core.
Worked examples
Dice for a strong overlap
(120 · 100 · 80)
| Sorensen-Dice coefficient | 0.727 |
| Jaccard index | 0.571 |
| Union size | 140 |
| Overlap coefficient | 0.800 |
Dice for a modest overlap
(45 · 60 · 30)
| Sorensen-Dice coefficient | 0.571 |
| Jaccard index | 0.400 |
| Union size | 75 |
| Overlap coefficient | 0.667 |
Dice for two large sets
(200 · 180 · 150)
| Sorensen-Dice coefficient | 0.789 |
| Jaccard index | 0.652 |
| Union size | 230 |
| Overlap coefficient | 0.833 |
Counting the overlap twice
The numerator counts every shared element twice - once as a member of the first set, once as a member of the second - and the denominator is the total membership of both sets counted the same way. Dice is therefore the share of all memberships that are shared memberships. In the first worked example, sets of 120 and 100 elements share 80: the shared memberships are counted against the total membership of both sets together, and the coefficient is 0.727. Framed that way, the number reads naturally as a percentage-like score, which is one reason it has outlived several more elaborate similarity measures.
The double counting has a precise relationship to the Jaccard index, which counts the intersection once against the union. On the same sets the two are linked by a fixed formula, and Dice always comes out higher - in the first example, 0.727 against a Jaccard of 0.571. Neither is wrong; they are different answers to 'how much overlap', with Dice weighting the shared core more heavily. What matters is never mixing the two in one comparison, a reporting error that survives in the literature to this day.
The third example shows Dice at scale: sets of 200 and 180 sharing 150 elements score 0.789, with a Jaccard of 0.652 on a union of 230. Large sets with deep overlap are where the coefficient earns its keep in modern applications, from comparing document vocabularies to scoring how well a predicted image segment matches the real one.
- Dice = 2 x |A and B| / (|A| + |B|), running from 0 (disjoint) to 1 (identical).
- Dice always reads at or above the Jaccard index on the same pair of sets.
- In machine learning the Dice coefficient is exactly the F1 score of a binary prediction.
- The overlap coefficient divides the intersection by the smaller set instead.
Dice versus Jaccard on the same sets
Jaccard asks: of everything that appears in either set, what share appears in both? Dice asks: of all the memberships in both sets, what share is shared? The first example separates them cleanly - a union of 140 elements containing an intersection of 80 gives Jaccard 0.571, while the membership framing gives Dice 0.727. The gap between the two grows as the sets grow more unequal in size, because the union punishes unmatched elements of the larger set more heavily than the membership count does.
Choosing between them is choosing what to penalise. If stray elements in one set are as blameworthy as missing elements - a retrieved document set against the relevant set, say - Jaccard's union framing is the stricter and often fairer judge. If the shared core is what matters and the sets' outer fringes are noisy by nature - species lists from two surveys, symptom sets, vocabularies - Dice's generosity toward the core matches the scientific question better. The second example, sets of 45 and 60 sharing 30, scores Dice 0.571 against Jaccard 0.400: the same evidence, two defensible verdicts, and a methods section that owes its reader the name of the one it used.
The overlap coefficient, also reported here, answers a third question: how much of the smaller set is contained in the larger? In the first example it is 0.800 - four fifths of the smaller set lives inside the bigger one - a containment statement that neither Dice nor Jaccard makes directly, and the right one when one set is supposed to be a subset of the other.
| Measure | Formula in words | First example |
|---|---|---|
| Dice | Twice the intersection over both sizes | 0.727 |
| Jaccard | Intersection over union | 0.571 |
| Overlap | Intersection over the smaller set | 0.800 |
Worked examples
Example 1: Set A size 120; Set B size 100; Intersection size 80. Sorensen-Dice coefficient = 0.727. Supporting values: Jaccard index 0.571; Union size 140; Overlap coefficient 0.800. Inputs: set A holds 120 elements, set B holds 100 and the intersection holds 80. Union: 120 + 100 - 80 = 140 elements. Shared weight: 2 x 80 / (120 + 100) = 0.727. Dice coefficient result: 0.727 - a Jaccard index of 0.571 on the same sets.
Example 2: Set A size 45; Set B size 60; Intersection size 30. Sorensen-Dice coefficient = 0.571. Supporting values: Jaccard index 0.400; Union size 75; Overlap coefficient 0.667. Inputs: set A holds 45 elements, set B holds 60 and the intersection holds 30. Union: 45 + 60 - 30 = 75 elements. Shared weight: 2 x 30 / (45 + 60) = 0.571. Dice coefficient result: 0.571 - a Jaccard index of 0.400 on the same sets.
Example 3: Set A size 200; Set B size 180; Intersection size 150. Sorensen-Dice coefficient = 0.789. Supporting values: Jaccard index 0.652; Union size 230; Overlap coefficient 0.833. Inputs: set A holds 200 elements, set B holds 180 and the intersection holds 150. Union: 200 + 180 - 150 = 230 elements. Shared weight: 2 x 150 / (200 + 180) = 0.789. Dice coefficient result: 0.789 - a Jaccard index of 0.652 on the same sets.
The F1 connection
In classification and segmentation work, Dice appears under a second identity: with one set as predictions and the other as ground truth, the Dice coefficient is exactly the F1 score - the harmonic mean of precision and recall. The intersection is the true positives, counted once for precision's sake and once for recall's, which is precisely Dice's double counting. A segmentation model scoring a Dice of 0.789, like the third example's sets, is reporting an F1 of the same value, and the medical imaging literature's 'Dice score' and the machine learning literature's F1 are one statistic wearing two names.
That identity explains the coefficient's modern ubiquity. It also imports F1's known behaviour: Dice rewards balanced performance and is dragged down by whichever of precision or recall is weaker, because the harmonic structure punishes imbalance. A model that over-segments wildly or under-segments timidly both score poorly, which is the behaviour practitioners want from a single headline metric.
Where Dice misleads
Dice is a pure set measure: it sees membership and nothing else. It cannot tell a near-miss from a total miss - an element just outside the intersection counts exactly as much as one from another universe - and it is silent about the elements' importance. In ecological comparisons, where Dice began, a shared rare species and a shared ubiquitous one count identically, which later indices were invented to correct. In segmentation, a boundary error of one pixel and a missing structure both simply shrink the intersection.
Small sets deserve suspicion too. With sets of a handful of elements, one element more or less in the intersection swings the coefficient violently, and quoting three decimal places - as this page does for consistency - implies a precision the counts cannot support. The honest report pairs the coefficient with the three counts it came from: 120, 100 and 80 are the evidence behind 0.727, and they let any reader recompute, reinterpret or challenge the headline figure.
A brief history in two fields
Dice published the measure in Ecology in 1945 to quantify how strongly two species are associated across sampling sites; Sorensen's 1948 version, in Danish botanical literature, compared plant communities. For decades the coefficient lived in ecology and biogeography as a community-similarity index, computed by hand on species lists not unlike the second example's sets of 45 and 60.
Its second life began when information retrieval and then medical image analysis needed a forgiving overlap score, and it has since become the default segmentation metric in medical imaging challenges - a 1945 ecology statistic grading neural networks. The arithmetic never changed; only the sets did, from species lists to pixel masks. That durability is the mark of a measure that matches a real question: of everything these two collections contain, how much do they hold in common?
FAQs
What does the Dice coefficient measure?
The similarity of two sets: twice the size of their intersection divided by the sum of their sizes. It runs from 0 for disjoint sets to 1 for identical ones, and can be read as the share of all set memberships that are shared.
What Dice coefficient does the first worked example give?
Sets of 120 and 100 elements sharing 80 give a Dice of 0.727. The same pair scores a Jaccard of 0.571 on a union of 140, and an overlap coefficient of 0.800 against the smaller set.
Why is Dice always higher than Jaccard?
Because Dice counts the intersection twice - once for each set - while Jaccard counts it once against the union. The two are linked by a fixed formula, and on the second example's sets they read 0.571 and 0.400 respectively.
Is the Dice coefficient the same as the F1 score?
Yes, when the sets are predictions and ground truth. The intersection is the true positives, counted once for precision and once for recall - exactly Dice's double counting. A segmentation Dice of 0.789, like the third example, is an F1 of 0.789.
When should I use the overlap coefficient instead?
When the question is containment: how much of the smaller set sits inside the larger. In the first example the overlap coefficient is 0.800 - four fifths of the smaller set is contained - which neither Dice nor Jaccard states directly.
What are Dice's main limitations?
It sees membership only: near-misses count as total misses, all elements count equally regardless of importance, and with very small sets a single element swings the score. Always report the counts behind it - 200, 180 and 150 behind the third example's 0.789.