Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +25 -25
src/streamlit_app.py
CHANGED
|
@@ -452,31 +452,31 @@ if submitted:
|
|
| 452 |
patient_cov[c] = categorical_defaults.get(c, 0)
|
| 453 |
|
| 454 |
try:
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
|
| 481 |
st.caption(
|
| 482 |
"Choose the appropriate model from the left panel based on the outcome you want to predict. "
|
|
|
|
| 452 |
patient_cov[c] = categorical_defaults.get(c, 0)
|
| 453 |
|
| 454 |
try:
|
| 455 |
+
# Create one-hot design row matching training design columns
|
| 456 |
+
patient_design = make_patient_design_row(patient_cov, design_cols, cat_cols)
|
| 457 |
+
if isinstance(patient_design, tuple):
|
| 458 |
+
patient_design = patient_design[0] # keep only the DataFrame row
|
| 459 |
+
|
| 460 |
+
# Predict survival curve + landmarks
|
| 461 |
+
surv_fn, landmarks = predict_patient_survival(cph, patient_design, years=[3, 5, 10])
|
| 462 |
+
|
| 463 |
+
st.subheader("Individual adjusted survival curve")
|
| 464 |
+
fig, ax = plt.subplots(figsize=(8, 5))
|
| 465 |
+
surv_fn.plot(ax=ax, legend=False)
|
| 466 |
+
ax.set_title("Predicted adjusted survival curve")
|
| 467 |
+
ax.set_xlabel("Days")
|
| 468 |
+
ax.set_ylabel("Survival probability")
|
| 469 |
+
st.pyplot(fig, bbox_inches="tight")
|
| 470 |
+
plt.clf()
|
| 471 |
+
|
| 472 |
+
st.write("Landmark survival probabilities:")
|
| 473 |
+
for y in [3, 5, 10]:
|
| 474 |
+
s = landmarks.get(y, None)
|
| 475 |
+
if s is not None:
|
| 476 |
+
st.write(f"{y}-year survival: {100*s:.1f}%")
|
| 477 |
+
|
| 478 |
+
except Exception as e:
|
| 479 |
+
st.error(f"Survival prediction failed: {e}")
|
| 480 |
|
| 481 |
st.caption(
|
| 482 |
"Choose the appropriate model from the left panel based on the outcome you want to predict. "
|