Skip to content

Instantly share code, notes, and snippets.

@spotter
Created March 2, 2011 14:06
Show Gist options
  • Select an option

  • Save spotter/850981 to your computer and use it in GitHub Desktop.

Select an option

Save spotter/850981 to your computer and use it in GitHub Desktop.
Compute the adjusted rand_index
def rand_stat_adjusted(C, P):
"""Return Rand statistic.
C and P are two iterables.
"""
sz = len(C)
M = a = b = c= d = 0
for i in range(sz-1):
for j in range(i+1,sz):
M += 1
if C[i] == C[j]:
if P[i]==P[j]:
a += 1
else:
b += 1
else:
if P[i] == P[j]:
c += 1
else:
d += 1
expected = ((a+b)*(a+c))+((c+d)*(b+d))
RIA = ((M*(a+d))-expected) / float(M**2 - expected)
return RIA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment