Data Science · Klinik Klinische Datenanalyse & Machine Learning
Ansicht
Lerntiefe
Codeansicht
Farbschema

25 · Bewertung der Modellgüte und klinische Validierung

kalibrierung.png

Abbildung · Quellcode

kalibrierung

Erzeugt von fig_calibration() in module/25-modellguete-validierung/code/figures.py, Zeile 57–77.

Python
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")

← zurück zu Modul 25 · vollständige Datei ansehen