Free cookie consent management tool by TermsFeed Computing Dice dissimilarity using Python | Pythontic.com

Computing Dice dissimilarity using Python

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.

# 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:

Dice dissimilarity between crane and polar bear:0.33
Jaccard dissimilarity between crane and polar bear:0.5

 


Copyright 2025 © pythontic.com