Created
March 2, 2011 14:06
-
-
Save spotter/850981 to your computer and use it in GitHub Desktop.
Compute the adjusted rand_index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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