Skip to content
Snippets Groups Projects
Commit 01d900b9 authored by Ivan Pavlovich's avatar Ivan Pavlovich
Browse files

Modification du script de création des graphs pour utiliser le dossier avec les résultats générés

parent 01a7d8f4
No related branches found
No related tags found
No related merge requests found
testModel/results/graphs/ALL.png

69.1 KiB

testModel/results/graphs/LONG.png

68.5 KiB

testModel/results/graphs/MEDIUM.png

68.5 KiB

testModel/results/graphs/SHORT.png

68.5 KiB

testModel/results/graphs/VERY LONG.png

69.1 KiB

......@@ -2,48 +2,70 @@ import sys
import os
import matplotlib.pyplot as plt
import numpy as np
import json
import matplotlib.ticker as ticker
from matplotlib.ticker import MaxNLocator
# Ajouter le répertoire parent au chemin de recherche
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
from parsers.jsonParser import parseJsonFile
from variables.articles import LENGTH_CATEGORIES
from variables.models import MODELS
def get_result_filename(model):
return model.replace(" ", "_").replace("-", "_").replace(".", "_").replace("/", "-")
RESULTS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "./results"))
GRAPHS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "./results/graphs"))
length_categories = LENGTH_CATEGORIES
length_categories.append("ALL")
models = [model for model in MODELS.keys()]
metrics = ["TPR", "TNR", "Precision", "F1"]
for model in models:
print(get_result_filename(model))
models_results = {}
for model in models:
with open(f"{RESULTS_DIR}/{get_result_filename(model)}.json", "r", encoding="utf-8") as file:
data = json.load(file)
for length_category in length_categories:
values = []
for metric in metrics:
values.append(data["results"][length_category][metric])
data["results"][length_category] = values
models_results[model] = data["results"]
RESULTS_DIR_NAME = "./results"
RESULTS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), RESULTS_DIR_NAME))
print(models_results)
try:
results = parseJsonFile(f"{RESULTS_DIR}/zero_shot/v2/condensed_results.json")
print(results)
except Exception as e:
print(f"Error: {e}")
x = np.arange(len(models))
width = 0.2
data = results
models = [entry["model"] for entry in data]
categories = [entry["Name"] for entry in data[0]["data"]]
for length_category in length_categories:
fig, axes = plt.subplots(5, 1, figsize=(18, 50), sharey=True)
fig, ax = plt.subplots(figsize=(14, 8))
colors = ["skyblue", "orange", "green"]
metrics = ["TPR", "TNR", "Precision"]
bar_width = 0.2
x_positions = np.arange(len(models))
for i in range(len(metrics)):
ax.bar(x + i * width, np.array([models_results[model][length_category][i] for model in models]), width, label=metrics[i])
for i, category in enumerate(categories):
ax = axes[i]
for j, metric in enumerate(metrics):
values = []
for model_data in data:
category_data = next(item for item in model_data["data"] if item["Name"] == category)
values.append(category_data[metric])
ax.set_xticks(x + width * (len(metrics) / 2 - 0.5))
ax.set_xticklabels(models, rotation=20, ha="right")
ax.bar(x_positions + j * bar_width, values, width=bar_width, label=metric, color=colors[j])
ax.yaxis.set_major_locator(MaxNLocator(nbins=10))
ax.yaxis.set_minor_locator(ticker.AutoMinorLocator(2))
ax.set_title(category)
ax.set_xticks(x_positions + bar_width)
ax.set_xticklabels(models, rotation=15)
ax.set_ylabel("Valeur")
ax.set_ylabel("Score")
ax.set_title("Comparaison des modèles selon les métriques")
ax.legend()
# plt.tight_layout()
plt.savefig(f"{RESULTS_DIR}/zero_shot/v2/condensed_results.png")
\ No newline at end of file
plt.tight_layout()
plt.savefig(f"{GRAPHS_DIR}/{length_category}.png")
plt.close(fig)
\ No newline at end of file
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment