Skip to content
Snippets Groups Projects
Commit c5fd577f authored by Alice Brenon's avatar Alice Brenon
Browse files

Simplify script generating confusion matrices thanks to deabb234

parent b18d1f53
No related branches found
No related tags found
No related merge requests found
#!/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__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment