Last active
May 15, 2022 13:55
-
-
Save LouisdeBruijn/1db0283dc69916516e2948f0eefc3a6e to your computer and use it in GitHub Desktop.
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 cohen_kappa(ann1, ann2): | |
| """Computes Cohen kappa for pair-wise annotators. | |
| :param ann1: annotations provided by first annotator | |
| :type ann1: list | |
| :param ann2: annotations provided by second annotator | |
| :type ann2: list | |
| :rtype: float | |
| :return: Cohen kappa statistic | |
| """ | |
| count = 0 | |
| for an1, an2 in zip(ann1, ann2): | |
| if an1 == an2: | |
| count += 1 | |
| A = count / len(ann1) # observed agreement A (Po) | |
| uniq = set(ann1 + ann2) | |
| E = 0 # expected agreement E (Pe) | |
| for item in uniq: | |
| cnt1 = ann1.count(item) | |
| cnt2 = ann2.count(item) | |
| count = ((cnt1 / len(ann1)) * (cnt2 / len(ann2))) | |
| E += count | |
| return round((A - E) / (1 - E), 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment