-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_cohen_kappa.py
38 lines (30 loc) · 1.01 KB
/
calc_cohen_kappa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Calculates cohen kappa for the coding in this study
"""
from sklearn.metrics import cohen_kappa_score
import pandas as pd
def labels_to_numbers(labels1, labels2):
"""
Turn labels, eg. [tfoj, tfoz]
into numbers, e.g [0, 1]
"""
uniques = list(set(labels1 + labels2))
mapping = {}
for i, label in enumerate(uniques):
mapping[label] = i
return [mapping[label] for label in labels1], [mapping[label] for label in labels2], list(mapping.values())
def main():
"""do calc"""
print('main')
labels = pd.read_csv('coding_work\\different_codes.csv', header=None, names = ['first', 'second', 'domain'])
print(labels)
for domain in list(labels.domain.drop_duplicates()):
subdf = labels[labels.domain == domain]
y_1, y_2, all_labels = labels_to_numbers(list(subdf['first']), list(subdf['second']))
print(all_labels)
print(y_1)
print(y_2)
score = cohen_kappa_score(y_1, y_2)
print(domain, score)
print('called')
main()