-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.py
32 lines (25 loc) · 841 Bytes
/
metrics.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 11 12:49:04 2023
@author: maltejensen
"""
def FleissKappa(*args):
'''
Takes a variable number of predictions and one hot encodes and sum the votes, and return the
fleiss Kappa. Works only for 2 classes.
*args: Sequence of scans to calculate the Fleiss Kappa for
'''
def one_hot(X):
tmp = np.zeros(X.shape + (2,), dtype=np.int8)
tmp[X == 0, 0] = 1
tmp[X == 1, 1] = 1
return tmp
def aggregate_annotators(*args):
agg_out = np.zeros_like(one_hot(args[0]), dtype=np.int8)
for X in args:
agg_out += one_hot(X)
return agg_out
agg_out = aggregate_annotators(*args)
kappa = fleiss_kappa(agg_out.reshape(-1,2))
return kappa