Update app.py
Browse files
app.py
CHANGED
|
@@ -1098,56 +1098,57 @@ with tab_predict:
|
|
| 1098 |
|
| 1099 |
|
| 1100 |
# PR plot
|
| 1101 |
-
pr =
|
| 1102 |
fig_pr = make_fig(figsize=FIGSIZE, dpi=plot_dpi_screen)
|
| 1103 |
-
plt.plot(
|
| 1104 |
plt.xlabel("Recall")
|
| 1105 |
plt.ylabel("Precision")
|
| 1106 |
-
plt.title(f"PR Curve (AP = {
|
| 1107 |
|
| 1108 |
render_plot_with_download(
|
| 1109 |
fig_pr,
|
| 1110 |
-
title="PR curve",
|
| 1111 |
-
filename="
|
| 1112 |
export_dpi=export_dpi
|
| 1113 |
)
|
| 1114 |
|
|
|
|
| 1115 |
|
| 1116 |
-
# Calibration plot
|
| 1117 |
-
cal =
|
| 1118 |
fig_cal = make_fig(figsize=FIGSIZE, dpi=plot_dpi_screen)
|
| 1119 |
plt.plot(cal["prob_pred"], cal["prob_true"])
|
| 1120 |
plt.plot([0, 1], [0, 1])
|
| 1121 |
plt.xlabel("Mean predicted probability")
|
| 1122 |
plt.ylabel("Observed event rate")
|
| 1123 |
-
plt.title("
|
| 1124 |
|
| 1125 |
render_plot_with_download(
|
| 1126 |
fig_cal,
|
| 1127 |
-
title="
|
| 1128 |
-
filename="
|
| 1129 |
export_dpi=export_dpi
|
| 1130 |
)
|
| 1131 |
-
|
| 1132 |
-
|
| 1133 |
-
|
| 1134 |
-
dca = m["decision_curve"]
|
| 1135 |
fig_dca = make_fig(figsize=FIGSIZE, dpi=plot_dpi_screen)
|
| 1136 |
plt.plot(dca["thresholds"], dca["net_benefit_model"], label="Model")
|
| 1137 |
plt.plot(dca["thresholds"], dca["net_benefit_all"], label="Treat all")
|
| 1138 |
plt.plot(dca["thresholds"], dca["net_benefit_none"], label="Treat none")
|
| 1139 |
plt.xlabel("Threshold probability")
|
| 1140 |
plt.ylabel("Net benefit")
|
| 1141 |
-
plt.title("
|
| 1142 |
plt.legend()
|
| 1143 |
|
| 1144 |
render_plot_with_download(
|
| 1145 |
fig_dca,
|
| 1146 |
-
title="
|
| 1147 |
-
filename="
|
| 1148 |
export_dpi=export_dpi
|
| 1149 |
)
|
| 1150 |
|
|
|
|
| 1151 |
|
| 1152 |
except Exception as e:
|
| 1153 |
st.error(f"Could not compute external validation metrics: {e}")
|
|
|
|
| 1098 |
|
| 1099 |
|
| 1100 |
# PR plot
|
| 1101 |
+
pr = pr_ext
|
| 1102 |
fig_pr = make_fig(figsize=FIGSIZE, dpi=plot_dpi_screen)
|
| 1103 |
+
plt.plot(pr_ext["recall"], pr_ext["precision"])
|
| 1104 |
plt.xlabel("Recall")
|
| 1105 |
plt.ylabel("Precision")
|
| 1106 |
+
plt.title(f"External PR Curve (AP = {pr_ext['average_precision']:.3f})")
|
| 1107 |
|
| 1108 |
render_plot_with_download(
|
| 1109 |
fig_pr,
|
| 1110 |
+
title="External PR curve",
|
| 1111 |
+
filename="external_pr_curve.png",
|
| 1112 |
export_dpi=export_dpi
|
| 1113 |
)
|
| 1114 |
|
| 1115 |
+
|
| 1116 |
|
| 1117 |
+
# Calibration plot (external)
|
| 1118 |
+
cal = cal_ext
|
| 1119 |
fig_cal = make_fig(figsize=FIGSIZE, dpi=plot_dpi_screen)
|
| 1120 |
plt.plot(cal["prob_pred"], cal["prob_true"])
|
| 1121 |
plt.plot([0, 1], [0, 1])
|
| 1122 |
plt.xlabel("Mean predicted probability")
|
| 1123 |
plt.ylabel("Observed event rate")
|
| 1124 |
+
plt.title("External calibration curve")
|
| 1125 |
|
| 1126 |
render_plot_with_download(
|
| 1127 |
fig_cal,
|
| 1128 |
+
title="External calibration curve",
|
| 1129 |
+
filename="external_calibration_curve.png",
|
| 1130 |
export_dpi=export_dpi
|
| 1131 |
)
|
| 1132 |
+
|
| 1133 |
+
# DCA plot (external)
|
| 1134 |
+
dca = dca_ext
|
|
|
|
| 1135 |
fig_dca = make_fig(figsize=FIGSIZE, dpi=plot_dpi_screen)
|
| 1136 |
plt.plot(dca["thresholds"], dca["net_benefit_model"], label="Model")
|
| 1137 |
plt.plot(dca["thresholds"], dca["net_benefit_all"], label="Treat all")
|
| 1138 |
plt.plot(dca["thresholds"], dca["net_benefit_none"], label="Treat none")
|
| 1139 |
plt.xlabel("Threshold probability")
|
| 1140 |
plt.ylabel("Net benefit")
|
| 1141 |
+
plt.title("External decision curve analysis")
|
| 1142 |
plt.legend()
|
| 1143 |
|
| 1144 |
render_plot_with_download(
|
| 1145 |
fig_dca,
|
| 1146 |
+
title="External decision curve",
|
| 1147 |
+
filename="external_decision_curve.png",
|
| 1148 |
export_dpi=export_dpi
|
| 1149 |
)
|
| 1150 |
|
| 1151 |
+
|
| 1152 |
|
| 1153 |
except Exception as e:
|
| 1154 |
st.error(f"Could not compute external validation metrics: {e}")
|