"""Graphiques PNG à partir des mesures de scripts/mesurer_performances.py. Lancer : python -m scripts.graphiques resultats/ Produit dans ce dossier : 1_temps.png durées GPU vs CPU (échelle logarithmique) 2_qualite.png qualité du classement de chaque méthode testée 3_repartition.png scores des bons CV et des hors-domaine, seuils des libellés 4_carte_scores.png score de chaque CV sur chaque AVP (méthode retenue) Couleurs : palette catégorielle validée (daltonisme compris) - bleu = GPU / bons CV / méthode retenue, orange = CPU / hors domaine, gris = méthodes de comparaison. """ import csv import json import sys from pathlib import Path import matplotlib import matplotlib.ticker matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import LinearSegmentedColormap DOSSIER = Path(sys.argv[1]) if len(sys.argv) > 1 else sorted(Path("resultats").iterdir())[-1] # Palette de référence (mode clair) SURFACE, ENCRE, ENCRE_2, MUET = "#fcfcfb", "#0b0b0b", "#52514e", "#898781" GRILLE, AXE = "#e1e0d9", "#c3c2b7" BLEU, ORANGE, GRIS = "#2a78d6", "#eb6834", "#c3c2b7" RAMPE_BLEUE = ["#fcfcfb", "#cde2fb", "#9ec5f4", "#6da7ec", "#3987e5", "#256abf", "#184f95", "#0d366b"] plt.rcParams.update({ "font.family": ["Segoe UI", "DejaVu Sans"], "font.size": 10, "figure.facecolor": SURFACE, "axes.facecolor": SURFACE, "savefig.facecolor": SURFACE, "text.color": ENCRE, "axes.labelcolor": ENCRE_2, "xtick.color": MUET, "ytick.color": ENCRE_2, "axes.edgecolor": AXE, "axes.linewidth": 0.8, "grid.color": GRILLE, "grid.linewidth": 0.8, "axes.spines.top": False, "axes.spines.right": False, "axes.titleweight": "bold", "axes.titlesize": 12, "axes.titlelocation": "left", "axes.titlepad": 12, }) def lire(nom): f = DOSSIER / nom return json.loads(f.read_text(encoding="utf-8")) if f.exists() else None def sauver(fig, nom): fig.savefig(DOSSIER / nom, dpi=160, bbox_inches="tight") plt.close(fig) print(f" -> {DOSSIER / nom}") def duree(x: float) -> str: texte = f"{x:.2f} s" if x < 1 else (f"{x:.1f} s" if x < 60 else f"{x / 60:.1f} min") return texte.replace(".", ",") # ---------- 1. Durées GPU vs CPU ---------- def graphique_temps(): gpu, cpu = lire("temps_gpu.json"), lire("temps_cpu.json") if not gpu: return mediane = lambda t, cle, mode: (np.median([v["mediane_s"] for v in t[cle][mode].values()]) if t and t[cle].get(mode) else None) classe = lambda t, mode: (t["classement_23_cv"][mode]["mediane_s"] if t and t["classement_23_cv"].get(mode) else None) lignes = [ ("Démarrage : encodage des 24 AVP", lambda t: t and t["encodage_avps_s"]), ("/match sans reranker", lambda t: mediane(t, "match", "sans_reranker")), ("/match avec reranker", lambda t: mediane(t, "match", "avec_reranker")), ("Classer 23 CV sans reranker", lambda t: classe(t, "sans_reranker")), ("Classer 23 CV avec reranker", lambda t: classe(t, "avec_reranker")), ] fig, ax = plt.subplots(figsize=(9, 4.6)) y = np.arange(len(lignes)) h = 0.34 for decal, (t, nom, coul) in zip((-h / 2 - 0.02, h / 2 + 0.02), ((gpu, "GPU (RTX 3050)", BLEU), (cpu, "CPU seul", ORANGE))): for k, (_, f) in enumerate(lignes): v = f(t) if v is None: if t is cpu and cpu: ax.text(0.012, y[k] + decal, "non mesuré (~1 h 30 estimée)", va="center", fontsize=8.5, color=MUET) continue ax.barh(y[k] + decal, v, height=h, color=coul, label=nom if k == 0 else None) ax.text(v * 1.15, y[k] + decal, duree(v), va="center", fontsize=8.5, color=ENCRE_2) ax.set_xscale("log") ax.set_xlim(0.01, 20000) graduations = [0.01, 0.1, 1, 10, 60, 600, 3600] ax.set_xticks(graduations, ["0,01 s", "0,1 s", "1 s", "10 s", "1 min", "10 min", "1 h"]) ax.xaxis.set_minor_locator(matplotlib.ticker.NullLocator()) ax.set_yticks(y, [n for n, _ in lignes]) ax.set_ylim(len(lignes) - 0.3, -0.6) # inversé, avec de la marge en bas ax.tick_params(axis="y", length=0) ax.grid(axis="x") ax.set_axisbelow(True) ax.set_xlabel("Durée (échelle logarithmique)") ax.set_title("Vitesse du service : la carte graphique rend le reranker utilisable") ax.legend(frameon=False, loc="lower right") sauver(fig, "1_temps.png") # ---------- 2. Qualité du classement par méthode ---------- def graphique_qualite(): q = lire("qualite.json") if not q: return methodes = q["methodes"] mesures = [("cand_top1", "Candidat : bon AVP classé 1er"), ("cand_top3", "Candidat : bon AVP dans le top 3"), ("rec_top1", "Recruteur : bon CV classé 1er")] fig, axes = plt.subplots(1, 3, figsize=(12, 3.9), sharey=True) y = np.arange(len(methodes)) for ax, (cle, titre) in zip(axes, mesures): for k, m in enumerate(methodes): retenu = "retenu" in m["methode"] v = 100 * m[cle] ax.barh(y[k], v, height=0.62, color=BLEU if retenu else GRIS) ax.text(v + 1.5, y[k], f"{v:.0f} %", va="center", fontsize=8.5, color=ENCRE if retenu else ENCRE_2, fontweight="bold" if retenu else None) ax.set_xlim(0, 112) ax.set_xticks([0, 50, 100], ["0 %", "50 %", "100 %"]) ax.set_title(titre, fontsize=10, fontweight="normal", color=ENCRE) ax.grid(axis="x") ax.set_axisbelow(True) ax.tick_params(axis="y", length=0) etiquettes = [m["methode"] + (f" ⚠ {m['faux_positifs']} faux positif" if m["faux_positifs"] else "") for m in methodes] axes[0].set_yticks(y, etiquettes) axes[0].invert_yaxis() fig.suptitle(f"Qualité du classement ({q['nb_cv_etiquetes']} CV étiquetés, " f"{q['nb_hors_domaine']} hors domaine, 24 AVP)", x=0.01, ha="left", fontweight="bold", fontsize=12) fig.text(0.01, -0.03, "Bleu : méthode retenue. Avec 14 CV, un écart d'un CV (~7 points) " "n'est pas significatif.", fontsize=8.5, color=MUET) fig.tight_layout() sauver(fig, "2_qualite.png") # ---------- 3. Répartition des scores et libellés ---------- def graphique_repartition(): r = lire("repartition.json") if not r: return s_tb, s_b, s_p = r["seuils_libelle"] bons = [x["score"] for x in r["bons_cv_sur_leur_avp"]] hors = [x["score"] for x in r["hors_domaine_meilleur_avp"]] xmax = max(bons + hors) * 1.15 fig, ax = plt.subplots(figsize=(9, 3.4)) bandes = [(0, s_p, "Faible"), (s_p, s_b, "Partielle"), (s_b, s_tb, "Bonne"), (s_tb, xmax, "Très bonne")] for k, (a, b, nom) in enumerate(bandes): if k: ax.axvline(a, color=AXE, linewidth=0.8) ax.text((a + b) / 2, 2.05, nom, ha="center", fontsize=9, color=ENCRE_2) rng = np.random.default_rng(0) for valeurs, yb, coul, nom in ((bons, 1.2, BLEU, "Bons CV, sur leur AVP"), (hors, 0.4, ORANGE, "Hors domaine, sur leur meilleur AVP")): ax.scatter(valeurs, yb + rng.uniform(-0.18, 0.18, len(valeurs)), s=60, color=coul, edgecolors=SURFACE, linewidths=2, zorder=3, label=nom) ax.set_xlim(0, xmax) ax.set_ylim(0, 2.3) ax.set_yticks([1.2, 0.4], ["Bons CV", "Hors domaine"]) ax.tick_params(axis="y", length=0) ax.spines["left"].set_visible(False) ax.set_xlabel("Score /100 (méthode retenue)") ax.set_title(f"Libellés : seuils {s_p} / {s_b} / {s_tb} - aucun hors-domaine au-dessus de « Faible »") sauver(fig, "3_repartition.png") # ---------- 4. Carte des scores CV x AVP ---------- def graphique_carte(): f = DOSSIER / "scores_cv_avp.csv" if not f.exists(): return with open(f, encoding="utf-8-sig") as fh: lignes = list(csv.reader(fh, delimiter=";")) ids = lignes[0][3:] data = lignes[1:] m = np.array([[float(x) for x in l[3:]] for l in data]) fig, ax = plt.subplots(figsize=(12, 8.2)) cmap = LinearSegmentedColormap.from_list("bleu", RAMPE_BLEUE) im = ax.imshow(m, cmap=cmap, vmin=0, vmax=max(50, m.max()), aspect="auto") for c, l in enumerate(data): for cible in l[2].split("|"): if cible in ids: a = ids.index(cible) ax.add_patch(plt.Rectangle((a - 0.5, c - 0.5), 1, 1, fill=False, edgecolor=ORANGE, linewidth=2)) ax.set_xticks(range(len(ids)), [i.replace("3134-26-", "").replace("/SR", "") for i in ids], rotation=90, fontsize=8) ax.set_yticks(range(len(data)), [f"{l[0]} {l[1].split('(')[0].strip()[:42]}" for l in data], fontsize=8) ax.tick_params(length=0) for s in ax.spines.values(): s.set_visible(False) ax.set_xlabel("AVP (numéro 3134-26-…)") ax.set_title("Score de chaque CV sur chaque AVP - encadré orange : le bon AVP attendu") cb = fig.colorbar(im, ax=ax, fraction=0.025, pad=0.01) cb.set_label("Score /100") cb.outline.set_visible(False) sauver(fig, "4_carte_scores.png") if __name__ == "__main__": print(f"Graphiques dans {DOSSIER}") graphique_temps() graphique_qualite() graphique_repartition() graphique_carte()