Update src/streamlit_app.py
Browse files- src/streamlit_app.py +29 -31
src/streamlit_app.py
CHANGED
|
@@ -329,49 +329,47 @@ def load_data(csv_path=CSV_PATH, meta_path=META_PATH):
|
|
| 329 |
df, meta_df = load_data()
|
| 330 |
|
| 331 |
|
| 332 |
-
#
|
|
|
|
| 333 |
# -------------------------
|
| 334 |
st.sidebar.title("Feature Explorer - Advanced + SHAP")
|
| 335 |
|
| 336 |
-
#
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
"
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
|
|
|
| 350 |
|
| 351 |
-
|
|
|
|
|
|
|
|
|
|
| 352 |
|
|
|
|
| 353 |
|
| 354 |
# -------------------------
|
| 355 |
-
#
|
| 356 |
# -------------------------
|
| 357 |
-
st.title("Steel Authority of India Limited (SHAP-enabled)")
|
| 358 |
-
tabs = st.tabs([
|
| 359 |
-
"Features",
|
| 360 |
-
"Visualize",
|
| 361 |
-
"Correlations",
|
| 362 |
-
"Stats",
|
| 363 |
-
"Ensemble + SHAP",
|
| 364 |
-
"Target & Business Impact",
|
| 365 |
-
"Bibliography"
|
| 366 |
-
])
|
| 367 |
-
|
| 368 |
-
# ----- Features tab
|
| 369 |
with tabs[0]:
|
| 370 |
st.subheader("Feature metadata")
|
| 371 |
-
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
| 373 |
st.markdown(f"Total features loaded: **{df.shape[1]}** | Rows: **{df.shape[0]}**")
|
| 374 |
|
|
|
|
| 375 |
# ----- Visualize tab
|
| 376 |
with tabs[1]:
|
| 377 |
st.subheader("Feature visualization")
|
|
|
|
| 329 |
df, meta_df = load_data()
|
| 330 |
|
| 331 |
|
| 332 |
+
# -------------------------
|
| 333 |
+
# Sidebar filters & UI (fault-tolerant for minimal metadata)
|
| 334 |
# -------------------------
|
| 335 |
st.sidebar.title("Feature Explorer - Advanced + SHAP")
|
| 336 |
|
| 337 |
+
# Ensure meta_df always has at least placeholder columns
|
| 338 |
+
required_cols = ["feature_name", "source_type", "formula", "remarks"]
|
| 339 |
+
for col in required_cols:
|
| 340 |
+
if col not in meta_df.columns:
|
| 341 |
+
meta_df[col] = None
|
| 342 |
+
|
| 343 |
+
# Populate placeholders if file is just run summaries
|
| 344 |
+
if meta_df["feature_name"].isna().all():
|
| 345 |
+
meta_df["feature_name"] = df.columns
|
| 346 |
+
meta_df["source_type"] = [
|
| 347 |
+
"engineered" if any(x in c for x in ["poly", "pca", "roll", "lag"]) else "measured"
|
| 348 |
+
for c in df.columns
|
| 349 |
+
]
|
| 350 |
+
meta_df["formula"] = ""
|
| 351 |
+
meta_df["remarks"] = "auto-inferred synthetic feature metadata"
|
| 352 |
|
| 353 |
+
# Build sidebar safely
|
| 354 |
+
feat_types = sorted(meta_df["source_type"].dropna().unique().tolist())
|
| 355 |
+
selected_types = st.sidebar.multiselect("Feature type", feat_types, default=feat_types)
|
| 356 |
+
filtered_meta = meta_df[meta_df["source_type"].isin(selected_types)]
|
| 357 |
|
| 358 |
+
numeric_cols = df.select_dtypes(include=[np.number]).columns.tolist()
|
| 359 |
|
| 360 |
# -------------------------
|
| 361 |
+
# Features tab (robust)
|
| 362 |
# -------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
with tabs[0]:
|
| 364 |
st.subheader("Feature metadata")
|
| 365 |
+
st.dataframe(
|
| 366 |
+
filtered_meta[["feature_name", "source_type", "formula", "remarks"]]
|
| 367 |
+
.rename(columns={"feature_name": "Feature"}),
|
| 368 |
+
height=400
|
| 369 |
+
)
|
| 370 |
st.markdown(f"Total features loaded: **{df.shape[1]}** | Rows: **{df.shape[0]}**")
|
| 371 |
|
| 372 |
+
|
| 373 |
# ----- Visualize tab
|
| 374 |
with tabs[1]:
|
| 375 |
st.subheader("Feature visualization")
|