Update src/streamlit_app.py
Browse files- src/streamlit_app.py +15 -4
src/streamlit_app.py
CHANGED
|
@@ -483,12 +483,23 @@ with tabs[4]:
|
|
| 483 |
|
| 484 |
# Select only valid feature columns
|
| 485 |
cols_needed = [c for c in features if c in df.columns]
|
|
|
|
| 486 |
if target not in df.columns:
|
| 487 |
-
|
| 488 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
|
| 490 |
-
#
|
| 491 |
-
sub_df = df[cols_needed + [target]].sample(n=sample_size, random_state=42).reset_index(drop=True)
|
|
|
|
| 492 |
|
| 493 |
# Construct X and y
|
| 494 |
X = sub_df[cols_needed].copy()
|
|
|
|
| 483 |
|
| 484 |
# Select only valid feature columns
|
| 485 |
cols_needed = [c for c in features if c in df.columns]
|
| 486 |
+
# --- Build sub_df safely (force exact column match) ---
|
| 487 |
if target not in df.columns:
|
| 488 |
+
# try case-insensitive or partial fallback once
|
| 489 |
+
matches = [c for c in df.columns if target.lower() in c.lower()]
|
| 490 |
+
if len(matches) == 1:
|
| 491 |
+
target = matches[0]
|
| 492 |
+
st.info(f"Auto-corrected target to exact match: `{target}`")
|
| 493 |
+
elif len(matches) > 1:
|
| 494 |
+
st.warning(f"Multiple columns match '{target}': {matches}. Using first: {matches[0]}")
|
| 495 |
+
target = matches[0]
|
| 496 |
+
else:
|
| 497 |
+
st.error(f"Target `{target}` not found in dataframe columns.")
|
| 498 |
+
st.stop()
|
| 499 |
|
| 500 |
+
# Now build sub_df strictly
|
| 501 |
+
sub_df = df.loc[:, cols_needed + [target]].sample(n=sample_size, random_state=42).reset_index(drop=True)
|
| 502 |
+
|
| 503 |
|
| 504 |
# Construct X and y
|
| 505 |
X = sub_df[cols_needed].copy()
|