fgrezes's picture
scoring scripts
74d8708
raw history blame
No virus
808 Bytes
from sklearn.metrics import matthews_corrcoef
import numpy as np
def compute_MCC(references_dataset, predictions_dataset, ref_col='ner_tags', pred_col='pred_ner_tags'):
# computes the Matthews correlation coeff between two datasets
# sort by id
references_dataset = references_dataset.sort('unique_id')
predictions_dataset = predictions_dataset.sort('unique_id')
# check that tokens match
assert(references_dataset['tokens']==predictions_dataset['tokens'])
# the lists have to be flattened
flat_ref_tags = np.concatenate(references_dataset[ref_col])
flat_pred_tags = np.concatenate(predictions_dataset[pred_col])
mcc_score = matthews_corrcoef(y_true=flat_ref_tags,
y_pred=flat_pred_tags)
return(mcc_score)