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

Erzeugt von fig_decision_curve() in module/25-modellguete-validierung/code/figures.py, Zeile 80–99.
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_decision_curve(y_test, proba) -> None: thresholds = np.linspace(0.01, 0.50, 200) base_rate = float(np.mean(y_test)) nb_model = [net_benefit(y_test, proba, t) for t in thresholds] nb_all = [base_rate - (t / (1 - t)) * (1 - base_rate) for t in thresholds] nb_none = [0.0] * len(thresholds) fig, ax = plt.subplots(figsize=(7, 4.5)) ax.plot(thresholds, nb_model, color=PRIMARY, lw=2, label="Logistisches Modell") ax.plot(thresholds, nb_all, color=EVENT, lw=1.5, ls="-.", label="Alle behandeln") ax.plot(thresholds, nb_none, color=SECONDARY, lw=1.2, ls="--", label="Niemanden behandeln") ax.axhline(0, color="#CCCCCC", lw=0.8) ax.set_xlim(0.01, 0.50) ax.set_ylim(-0.05, None) ax.set_xlabel("Entscheidungsschwelle") ax.set_ylabel("Nettovorteil (Net Benefit)") ax.set_title("Decision-Curve-Analyse: Klinischer Nutzen des Modells (rekalibriert)") ax.legend(loc="upper right") save(fig, ASSETS / "decision_curve.png")