diff --git a/scripts/ML/evaluate.py b/scripts/ML/evaluate.py new file mode 100755 index 0000000000000000000000000000000000000000..104cdad5d97c4baff1b1629a7ac3a253c797e073 --- /dev/null +++ b/scripts/ML/evaluate.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +from EDdA.classification import heatmap +from EDdA.store import preparePath +import GEODE.discursive as discursive +import pandas +from sklearn.metrics import classification_report, confusion_matrix +from sys import argv + +def evaluate(truth, predictions, outputDirectory): + matrix = confusion_matrix(truth, + predictions, + labels=list(discursive.functions), + normalize='true') + heatmap(matrix, + preparePath(f"{outputDirectory}/confusion.png"), + labels=discursive.functions) + with open(f"{outputDirectory}/report.json", 'w') as json: + print(classification_report(truth, predictions, output_dict=True), + file=json) + with open(f"{outputDirectory}/report.txt", 'w') as txt: + print(classification_report(truth, predictions), + file=txt) + +if __name__ == '__main__': + truth = pandas.read_csv(argv[1], sep='\t') + predictions = pandas.read_csv(argv[2], sep='\t') + evaluate(truth['paragraphFunction'], predictions['label'], argv[3])