File size: 339 Bytes
f811c13
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
import sklearn.metrics
import numpy as np

def f1_macro(targets, predictions):
    targets, predictions = np.asarray(targets), np.asarray(predictions)
    unique_labels = np.unique(np.concatenate((targets, predictions)))
    return {"f1_macro": 100 * sklearn.metrics.f1_score(targets, predictions, labels=unique_labels, average='macro')}