31 · Verarbeitung klinischer Freitexte mit LLMs
text_roc.png
Abbildung · Quellcode

Erzeugt von fig_text_roc() in module/31-klinische-texte-llm/code/figures.py, Zeile 80–93.
Python
Python-Code: in eine Datei mit Endung
.py schreiben und mit dem ▶-Knopf in VS Code ausführen – oder Zeile für Zeile in die Python-Konsole. Setzt die in Modul 02 eingerichtete Umgebung voraus.def fig_text_roc(pipe: Pipeline, X_test, y_test) -> None: """ROC curve for the text classifier on the held-out test set.""" proba = pipe.predict_proba(X_test)[:, 1] fpr, tpr, _ = roc_curve(y_test, proba) auc = roc_auc_score(y_test, proba) fig, ax = plt.subplots(figsize=(5.5, 5)) ax.plot(fpr, tpr, color=PRIMARY, lw=2, label=f"TF-IDF + LogReg (AUC = {auc:.2f})") ax.plot([0, 1], [0, 1], color=SECONDARY, lw=0.9, ls="--", label="Zufallsklassifikator") ax.set_xlabel("Falsch-Positiv-Rate (1 – Spezifität)") ax.set_ylabel("Richtig-Positiv-Rate (Sensitivität)") ax.set_title("ROC-Kurve: Textklassifikator für Verschlechterung") ax.legend(loc="lower right") save(fig, ASSETS / "text_roc.png")