25 · Bewertung der Modellgüte und klinische Validierung
kalibrierung.png
Abbildung · Quellcode

Erzeugt von fig_calibration() in module/25-modellguete-validierung/code/figures.py, Zeile 57–77.
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_calibration(y_test, proba) -> None: """Calibration curve on RECALIBRATED probabilities. `proba` here must already be the CalibratedClassifierCV output (see main()) — class_weight="balanced" inflates raw predict_proba() and would make this figure show a miscalibrated model regardless of true quality. """ brier = brier_score_loss(y_test, proba) frac_pos, mean_pred = calibration_curve(y_test, proba, n_bins=10) fig, ax = plt.subplots(figsize=(6, 5)) ax.plot([0, 1], [0, 1], color=SECONDARY, lw=1, ls="--", label="Perfekte Kalibrierung") ax.plot(mean_pred, frac_pos, "o-", color=PRIMARY, lw=1.8, label=f"Logistisches Modell (rekalibriert)\n(Brier Score = {brier:.3f})") ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.set_xlabel("Vorhergesagte Wahrscheinlichkeit") ax.set_ylabel("Beobachteter Ereignisanteil") ax.set_title("Kalibrierungskurve: Modell (nach Rekalibrierung) vs. Ideal") ax.legend(loc="upper left") save(fig, ASSETS / "kalibrierung.png")