Update src/streamlit_app.py
Browse files- src/streamlit_app.py +16 -1
src/streamlit_app.py
CHANGED
|
@@ -651,7 +651,15 @@ with tabs[4]:
|
|
| 651 |
for fam in families_to_try:
|
| 652 |
log(f"Tuning family: {fam}")
|
| 653 |
st.caption(f"Tuning family: {fam}")
|
| 654 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 655 |
# --- Leaderboard
|
| 656 |
lb = pd.DataFrame([{"family": r["family"], "cv_r2": r["cv_score"], "params": r["best_params"]} for r in tuned_results])
|
| 657 |
lb = lb.sort_values("cv_r2", ascending=False).reset_index(drop=True)
|
|
@@ -675,6 +683,13 @@ with tabs[4]:
|
|
| 675 |
kf = KFold(n_splits=5, shuffle=True, random_state=42)
|
| 676 |
base_models, oof_preds = [], pd.DataFrame(index=X_sel.index)
|
| 677 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 678 |
for fam, entry in [(r["family"], r) for r in tuned_results if r.get("model_obj")]:
|
| 679 |
model_obj = entry["model_obj"]
|
| 680 |
oof = np.zeros(X_sel.shape[0])
|
|
|
|
| 651 |
for fam in families_to_try:
|
| 652 |
log(f"Tuning family: {fam}")
|
| 653 |
st.caption(f"Tuning family: {fam}")
|
| 654 |
+
result = tune_family(fam, X, y, n_trials=max_trials)
|
| 655 |
+
model_obj = result.get("model_obj")
|
| 656 |
+
|
| 657 |
+
# ✅ Fix: ensure model is safe to access before fitting
|
| 658 |
+
if hasattr(model_obj, "estimators_"):
|
| 659 |
+
delattr(model_obj, "estimators_") # clear stale ref if any
|
| 660 |
+
result["model_obj"] = model_obj
|
| 661 |
+
tuned_results.append(result)
|
| 662 |
+
|
| 663 |
# --- Leaderboard
|
| 664 |
lb = pd.DataFrame([{"family": r["family"], "cv_r2": r["cv_score"], "params": r["best_params"]} for r in tuned_results])
|
| 665 |
lb = lb.sort_values("cv_r2", ascending=False).reset_index(drop=True)
|
|
|
|
| 683 |
kf = KFold(n_splits=5, shuffle=True, random_state=42)
|
| 684 |
base_models, oof_preds = [], pd.DataFrame(index=X_sel.index)
|
| 685 |
|
| 686 |
+
# Prevent premature __len__() access on unfitted ensemble models
|
| 687 |
+
for r in tuned_results:
|
| 688 |
+
m = r.get("model_obj")
|
| 689 |
+
if m and hasattr(m, "__len__") and not hasattr(m, "estimators_"):
|
| 690 |
+
m.__len__ = lambda self=m: 0
|
| 691 |
+
|
| 692 |
+
|
| 693 |
for fam, entry in [(r["family"], r) for r in tuned_results if r.get("model_obj")]:
|
| 694 |
model_obj = entry["model_obj"]
|
| 695 |
oof = np.zeros(X_sel.shape[0])
|