Computing Dice dissimilarity using Python

The Dice dissimilarity between two vectors is given by the formula b+c/2a+b+c whose entries are from the contingency table. The Dice dissimilarity gives more weightage to the case of both the vectors having True for corresponding elements.

Distance Calculcations Updated 23 Jul 2025 1 min read

Overview

  • The Dice dissimilarity between two vectors i and j containing Boolean elements is given by b+c/2a+b+c.
  • When compared with Jaccard dissimilarity the denominator of Dice dissimilarity differs in the weightage given to component a. In case of Dice the dissimilarity decreases more when both the objects have the same properties present. Dice gives double weightage to the binary combination 11 for both the objects.
  • The contingency table for two vectors having binary variables is formed by

Contingency Table for Dice Dissimilarity

Example

The example finds the Dice dissimilarity between Crane and Polar bear. Dice gives double the weightage to the fact that both Crane and Polar bear feed on fish and both are white in colour.

python
# Example Python program that computes the Dice dissimilarity

            # between two given species using the function dice()

            # from the distance module of the SciPy libray

            import scipy.spatial.distance as dist

features_crane             = [1, 1, 1, 0, 1]

            features_polarbear         = [1, 1, 0, 0, 0]

# Find Dice dissimilarity

            dis = dist.dice(features_crane, features_polarbear)

            print("Dice dissimilarity between crane and polar bear:{:.2}".format(dis))

# Find Jaccard dissimilarity to compare with Dice dissimilarity

            dis = dist.jaccard(features_crane, features_polarbear)

            print("Jaccard dissimilarity between crane and polar bear:{:.2}".format(dis))

Output

Output
Dice dissimilarity between crane and polar bear:0.33

            Jaccard dissimilarity between crane and polar bear:0.5