All problems
Dice Coefficient of Sets
Problem
The Dice coefficient is 2 |A intersect B| / (|A| + |B|) and relates to Jaccard by Dice = 2J / (1 + J). Return 1.0 when both sets are empty.
Given two lists of elements, return the coefficient.
Hint
It is the harmonic-style overlap ratio of set sizes.
Test cases
case 1
in: [[1,2],[2,3]]
expected: 0.5
case 2
in: [[1,2],[1,2]]
expected: 1
case 3
in: [[1],[2]]
expected: 0
Starter codePython
def dice_coefficient_of_sets(a, b):
# Your code here
pass3 test cases · run your code against them in the editor