# Is the Dice coefficient the same as accuracy?

I have come across the Dice coefficient for volume similarity and accuracy. It seems to me that these two measures are the same. Is that correct?

These are not the same thing and they are often used in different contexts. The Dice score is often used to quantify the performance of image segmentation methods. There you annotate some ground truth region in your image and then make an automated algorithm to do it. You validate the algorithm by calculating the Dice score, which is a measure of how similar the objects are. So it is the size of the overlap of the two segmentations divided by the total size of the two objects. Using the same terms as describing accuracy, the Dice score is:

$$\frac{2\cdot \text{number of true positives}}{2 \cdot \text{number of true positives + number of false positives + number of false negatives}}$$

To explain the terms:

• Number of true positives: number of positive points that your method classifies as positive
• Number of false positives: number of negative points that your method classifies as positive
• Number of positives: total number of positives points

The Dice score is not only a measure of how many positives you find, but it also penalizes for the false positives that the method finds, similar to precision. So it is more similar to precision than accuracy. The only difference is the denominator, where you have the total number of positives instead of only the positives that the method finds. So the Dice score is also penalizing for the positives that your algorithm/method could not find.

Edit: In the case of image segmentation, let's say that you have a mask with ground truth, let's call the mask $$A$$ like you suggest. So the mask has values 1 in the pixels where there is something you are trying to find and else zero. Now you have an algorithm to generate image/mask $$B$$, which also has to be a binary image, i.e. you create a mask for you segmentation. Then we have the following:

• Number of positives is the total number of pixels that have intensity 1 in image $$A$$
• Number of true positives is the total number of pixels which have the value 1 in both $$A$$ and $$B$$. So it the intersection of the regions of ones in $$A$$ and $$B$$. It is the same as using the AND operator on $$A$$ and $$B$$.
• Number of false positives is the number of pixels which appear as 1 in $$B$$ but zero in $$A$$.

If you are doing this for a publication, then write Dice with a capital D, because it is named after a guy named Dice.

EDIT: Regarding the comment about a correction: I do not use the traditional formula to calculate the Dice coefficient, but if I translate it to the notation in the other answer it becomes:

$$\text{Dice score} = \frac{2\cdot|A\cap B|}{2\cdot|A\cap B| + |B\backslash A| + |A\backslash B|} = \frac{2\cdot|A\cap B|}{|A| + |B|}$$

Which is equivalent to the traditional definition. It is more convenient to write it the way I wrote it originally to state the formula in terms of false positives. The backslash is the set minus.

• Thanks for the reply. Exactly for image segmentation comparison. So, this dice score is used, let say, give image A and image B. Image A is the ground true (0 or 1), and image B is my segmentation. So, what is the total number of positives(1), is that the number of 1 in A + number of 1 in B?? I am a bit confused here. Same as false positive Commented Feb 11, 2016 at 17:45
• @RockTheStar I'll edit my answer to account for image segmentation. Commented Feb 11, 2016 at 17:53
• Great, thanks! Will implement this and look at the result Commented Feb 11, 2016 at 20:11
• @Gumeo you might want to fix or at least explain your answer, please see my new answer for details Commented Dec 31, 2016 at 19:36
• @whuber I'll add it. Commented Jan 17, 2022 at 9:49

The Dice coefficient (also known as Dice similarity index) is the same as the F1 score, but it's not the same as accuracy. The main difference might be the fact that accuracy takes into account true negatives while Dice coefficient and many other measures just handle true negatives as uninteresting defaults (see The Basics of Classifier Evaluation, Part 1).

As far as I can tell, the Dice coefficient isn't computed as described by a previous answer, which actually contains the formula for the Jaccard index (also known as "intersection over union" in computer vision).

\begin{align*} \text{Dice}(A,B) &= \frac{2|A\cdot B|}{ |A| + |B| } \\ F1(A,B) &= \frac{2}{|A|/|A \cdot B| + |B|/|A\cdot B|} \\ \text{Jaccard}(A,B) &= \frac{|A\cdot B|}{|\max(A,B)|} = \frac{|A\cdot B|}{|A|+|B|-|A\cdot B|}\\ \text{Accuracy}(A,B) &= \frac{|A\cdot B|+|\overline{A} \cdot \overline{B}|}{|\text{All}|} \\ \end{align*}

Where $$A,B$$ binary vectors (with values of 1 for elements inside a group and 0 otherwise), one signify the ground truth and the other signify the classification result, and $$All$$ is just all elements considerred (a binary vector of 1's of the same length). For example, $$|A \cdot B|$$ (inner product of $$A$$ and $$B$$) is the number of true positives, $$|\overline{A} \cdot \overline{B}|$$ (inner product of the complement of $$A$$ and the complement of $$B$$) is the number of true negatives.

The Dice coefficient and Jaccard index are monotonically related, and the Tversky index generalizes them both, to read more about it see F-scores, Dice, and Jaccard set similarity.

The Dice coefficient is also the harmonic mean of Sensitivity and Precision, to see why it makes sense, read Why is the F-Measure a harmonic mean and not an arithmetic mean of the Precision and Recall measures?.

To read more about many of the terms in this answer and their relationships, see Evaluation of binary classifiers.

• Can you explain the Jaccard part that equates |max(a,b)|==|union(a,b)|? Looks like a mistake, but please correct me. Commented Feb 22, 2022 at 21:54
• @ldmtwo "A,B binary vectors (with values of 1 for elements inside a group and 0 otherwise)". max(A,B) is like an OR operation between indicator vector, and $|\cdot|$ is just counting how many elements are in both groups Commented Mar 1, 2022 at 19:10

The Dice coefficient (also known as the Sørensen–Dice coefficient and F1 score) is defined as two times the area of the intersection of A and B, divided by the sum of the areas of A and B: Dice = 2 |A∩B| / (|A|+|B|) = 2 TP / (2 TP + FP + FN) (TP=True Positives, FP=False Positives, FN=False Negatives) Dice score is a performance metric for image segmentation problems. This is different from accuracy where the objective is to match the values, unlike dice which matches the value + position.