From c5fd577f5c47a93c82f78d58b73fc0de7280fe3b Mon Sep 17 00:00:00 2001 From: Alice BRENON <alice.brenon@ens-lyon.fr> Date: Mon, 4 Apr 2022 15:59:11 +0200 Subject: [PATCH] Simplify script generating confusion matrices thanks to deabb23468 --- scripts/confusionMatrices.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/scripts/confusionMatrices.py b/scripts/confusionMatrices.py index a850740..2e07dd2 100644 --- a/scripts/confusionMatrices.py +++ b/scripts/confusionMatrices.py @@ -1,21 +1,11 @@ #!/usr/bin/env python3 from EDdA import data +from EDdA.store import preparePath from EDdA.classification import confusionMatrix, metrics, toPNG, topNGrams import os import sys -def preparePath(root, source, n, ranks, metricName): - path = "{root}/confusionMatrix/{inputHash}/{n}grams_top{ranks}_{name}.png".format( - root=root, - inputHash=source.hash, - n=n, - ranks=ranks, - name=metricName - ) - os.makedirs(os.path.dirname(path), exist_ok=True) - return path - def __syntax(this): print( "Syntax: {this} {required} {optional}".format( @@ -27,13 +17,14 @@ def __syntax(this): ) sys.exit(1) -def __compute(sourcePath, ns, ranksToTry, metricNames, outputDir): +def __compute(sourcePath, ns, ranksToTry, metricNames, root): source = data.load(sourcePath) + path = f"{root}/confusionMatrix/{source.hash}" for n in ns: for ranks in ranksToTry: vectorizer = topNGrams(source, n, ranks) for name in metricNames: - imagePath = preparePath(outputDir, source, n, ranks, name) + imagePath = preparePath(f"{path}/{n}grams_top{ranks}_{name}.png") toPNG(confusionMatrix(vectorizer, metrics[name]), imagePath) if __name__ == '__main__': -- GitLab