23 · Einführung in das maschinelle Lernen
roc_kurve.png
Abbildung · Quellcode

Erzeugt von fig_roc() in module/23-machine-learning/code/figures.py, Zeile 39–55.
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_roc(y_test, proba) -> None: fpr, tpr, _ = roc_curve(y_test, proba) auc_val = roc_auc_score(y_test, proba) fig, ax = plt.subplots(figsize=(6, 6)) ax.plot(fpr, tpr, color=PRIMARY, linewidth=2.2, label=f"Logistische Regression (AUC = {auc_val:.3f})") ax.plot([0, 1], [0, 1], color=SECONDARY, linestyle="--", linewidth=1.0, label="Zufallsklassifikator (AUC = 0.500)") ax.fill_between(fpr, tpr, alpha=0.10, color=PRIMARY) ax.set_xlabel("Falsch-Positiv-Rate (1 − Spezifität)") ax.set_ylabel("Richtig-Positiv-Rate (Sensitivität)") ax.set_title(f"ROC-Kurve: 30-Tage-Mortalität\n(Testdaten, N = {len(y_test)})") ax.legend(loc="lower right") ax.set_xlim(0, 1) ax.set_ylim(0, 1.02) save(fig, ASSETS / "roc_kurve.png")