All problems
Adjusted Rand Index
Problem
Compute the adjusted Rand index between two label lists using pair counts:
ARI = (sum_ij C(n_ij, 2) - E) / (0.5 * (sum_i C(a_i, 2) + sum_j C(b_j, 2)) - E), where E = sum_i C(a_i, 2) * sum_j C(b_j, 2) / C(n, 2).
Return 1.0 when the denominator is 0, and 0.0 for empty input.
Hint
ARI corrects the Rand index for chance using counting pairs that fall in the same cluster.
Test cases
case 1
in: [[0,0,1,1],[0,0,1,1]]
expected: 1
case 2
in: [[0,0,1,1],[0,1,0,1]]
expected: -0.49999999999999994
case 3
in: [[0,0,1,1,2,2],[0,0,1,2,1,2]]
expected: 0.16666666666666669
case 4
in: [[],[]]
expected: 0
Starter codePython
def adjusted_rand_index(a, b):
# Your code here
pass4 test cases · run your code against them in the editor