Update app.py
Browse files
app.py
CHANGED
|
@@ -936,31 +936,34 @@ with tab_train:
|
|
| 936 |
|
| 937 |
if not is_admin():
|
| 938 |
st.info("Training and publishing are restricted. Use Predict + SHAP for inference.")
|
| 939 |
-
|
|
|
|
| 940 |
|
| 941 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 942 |
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
use_dimred = st.checkbox(
|
| 954 |
-
"Dimensionality reduction (TruncatedSVD) — reduces interpretability",
|
| 955 |
-
value=False
|
| 956 |
-
)
|
| 957 |
-
|
| 958 |
-
svd_components = st.slider(
|
| 959 |
-
"SVD components (only used if enabled)",
|
| 960 |
-
5, 300, 50, 5
|
| 961 |
-
) if use_dimred else 50
|
| 962 |
|
| 963 |
-
st.divider()
|
| 964 |
|
| 965 |
# ---------------- TRAIN ----------------
|
| 966 |
|
|
@@ -1409,7 +1412,7 @@ with tab_predict:
|
|
| 1409 |
"CNS Involvement",
|
| 1410 |
"Extramedullary Involvement",
|
| 1411 |
]
|
| 1412 |
-
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
|
@@ -1457,6 +1460,11 @@ with tab_predict:
|
|
| 1457 |
]
|
| 1458 |
NGS_COUNT_COL = "No. of ngs_mutation"
|
| 1459 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1460 |
# =========================
|
| 1461 |
# Fields managed by dedicated tabs (do NOT render duplicates in Core tab)
|
| 1462 |
# =========================
|
|
@@ -1470,6 +1478,10 @@ with tab_predict:
|
|
| 1470 |
|
| 1471 |
# NGS handled in NGS tab
|
| 1472 |
TAB_MANAGED_FIELDS.update([f for f in NGS_MARKERS if f in feature_cols])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1473 |
|
| 1474 |
# Optional marker counts: handled automatically
|
| 1475 |
if FISH_COUNT_COL in feature_cols:
|
|
@@ -1524,8 +1536,7 @@ with tab_predict:
|
|
| 1524 |
st.divider()
|
| 1525 |
st.subheader("Enter patient details to get prediction (Example: DOB → Age, Dx date → prediction)")
|
| 1526 |
|
| 1527 |
-
|
| 1528 |
-
DX_DATE_FEATURE = "Date of 1st Bone Marrow biopsy (Date of Diagnosis) " # keep exact if your schema has trailing space
|
| 1529 |
|
| 1530 |
from datetime import date
|
| 1531 |
|
|
@@ -1760,7 +1771,7 @@ with tab_predict:
|
|
| 1760 |
df_inf = st.session_state.df_inf
|
| 1761 |
if df_inf is None:
|
| 1762 |
st.info("Upload an inference Excel to run batch prediction / external validation.")
|
| 1763 |
-
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
|
@@ -2226,4 +2237,4 @@ with tab_predict:
|
|
| 2226 |
fig_b = plt.gcf()
|
| 2227 |
render_plot_with_download(fig_b, title="SHAP bar", filename="shap_bar_row.png", export_dpi=export_dpi)
|
| 2228 |
|
| 2229 |
-
|
|
|
|
| 936 |
|
| 937 |
if not is_admin():
|
| 938 |
st.info("Training and publishing are restricted. Use Predict + SHAP for inference.")
|
| 939 |
+
else:
|
| 940 |
+
st.markdown("### Feature reduction options")
|
| 941 |
|
| 942 |
+
use_feature_selection = st.checkbox(
|
| 943 |
+
"Drop columns that do not affect prediction (L1 feature selection)",
|
| 944 |
+
value=True,
|
| 945 |
+
key="train_use_feature_selection"
|
| 946 |
+
)
|
| 947 |
+
l1_C = st.slider(
|
| 948 |
+
"L1 selection strength (lower = fewer features)",
|
| 949 |
+
0.01, 10.0, 1.0, 0.01
|
| 950 |
+
) if use_feature_selection else 1.0
|
| 951 |
+
|
| 952 |
+
use_dimred = st.checkbox(
|
| 953 |
+
"Dimensionality reduction (TruncatedSVD) — reduces interpretability",
|
| 954 |
+
value=False
|
| 955 |
+
)
|
| 956 |
|
| 957 |
+
svd_components = st.slider(
|
| 958 |
+
"SVD components (only used if enabled)",
|
| 959 |
+
5, 300, 50, 5
|
| 960 |
+
) if use_dimred else 50
|
| 961 |
+
|
| 962 |
+
st.divider()
|
| 963 |
+
|
| 964 |
+
# then keep your file uploader + training button + publish block here
|
| 965 |
+
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 966 |
|
|
|
|
| 967 |
|
| 968 |
# ---------------- TRAIN ----------------
|
| 969 |
|
|
|
|
| 1412 |
"CNS Involvement",
|
| 1413 |
"Extramedullary Involvement",
|
| 1414 |
]
|
| 1415 |
+
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
|
|
|
| 1460 |
]
|
| 1461 |
NGS_COUNT_COL = "No. of ngs_mutation"
|
| 1462 |
|
| 1463 |
+
|
| 1464 |
+
AGE_FEATURE = "Age (years)"
|
| 1465 |
+
DX_DATE_FEATURE = "Date of 1st Bone Marrow biopsy (Date of Diagnosis) " # keep exact if your schema has trailing space
|
| 1466 |
+
|
| 1467 |
+
|
| 1468 |
# =========================
|
| 1469 |
# Fields managed by dedicated tabs (do NOT render duplicates in Core tab)
|
| 1470 |
# =========================
|
|
|
|
| 1478 |
|
| 1479 |
# NGS handled in NGS tab
|
| 1480 |
TAB_MANAGED_FIELDS.update([f for f in NGS_MARKERS if f in feature_cols])
|
| 1481 |
+
|
| 1482 |
+
DROPDOWN_FIELDS = [f for f in DROPDOWN_FIELDS if f not in TAB_MANAGED_FIELDS]
|
| 1483 |
+
YESNO_FIELDS = [f for f in YESNO_FIELDS if f not in TAB_MANAGED_FIELDS] # optional
|
| 1484 |
+
|
| 1485 |
|
| 1486 |
# Optional marker counts: handled automatically
|
| 1487 |
if FISH_COUNT_COL in feature_cols:
|
|
|
|
| 1536 |
st.divider()
|
| 1537 |
st.subheader("Enter patient details to get prediction (Example: DOB → Age, Dx date → prediction)")
|
| 1538 |
|
| 1539 |
+
|
|
|
|
| 1540 |
|
| 1541 |
from datetime import date
|
| 1542 |
|
|
|
|
| 1771 |
df_inf = st.session_state.df_inf
|
| 1772 |
if df_inf is None:
|
| 1773 |
st.info("Upload an inference Excel to run batch prediction / external validation.")
|
| 1774 |
+
st.stop()
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
|
|
|
| 2237 |
fig_b = plt.gcf()
|
| 2238 |
render_plot_with_download(fig_b, title="SHAP bar", filename="shap_bar_row.png", export_dpi=export_dpi)
|
| 2239 |
|
| 2240 |
+
|