Spaces:
Build error
Build error
feat: train all models on full data and save their paths
Browse files
app/training/train_classifier.py
CHANGED
|
@@ -178,9 +178,23 @@ def train(
|
|
| 178 |
title=f"Best: {best_name}",
|
| 179 |
)
|
| 180 |
|
| 181 |
-
# ── Train
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
# ── Feature importance ─────────────────────────
|
| 186 |
importance_data = _extract_importance(best_model, feature_cols)
|
|
@@ -215,6 +229,7 @@ def train(
|
|
| 215 |
json_results["_n_features"] = X.shape[1]
|
| 216 |
json_results["_n_folds"] = n_folds
|
| 217 |
json_results["_data_leakage_fix"] = "duration_sec and sample_rate removed from features (v2)"
|
|
|
|
| 218 |
if importance_data:
|
| 219 |
json_results["_feature_importance"] = {
|
| 220 |
name: round(imp, 6) for name, imp in importance_data
|
|
|
|
| 178 |
title=f"Best: {best_name}",
|
| 179 |
)
|
| 180 |
|
| 181 |
+
# ── Train ALL models on full data ────────────────
|
| 182 |
+
all_model_paths: dict[str, str] = {}
|
| 183 |
+
for name, model in candidates:
|
| 184 |
+
print(f"\nTraining final {name} on all {len(y)} samples...")
|
| 185 |
+
model.fit(X_scaled, y)
|
| 186 |
+
safe_name = name.lower().replace(" ", "_").replace("(", "").replace(")", "")
|
| 187 |
+
model_pkl = models_dir / f"model_{safe_name}.pkl"
|
| 188 |
+
with open(model_pkl, "wb") as f:
|
| 189 |
+
pickle.dump(model, f)
|
| 190 |
+
all_model_paths[name] = str(model_pkl)
|
| 191 |
+
print(f" → Saved: {model_pkl}")
|
| 192 |
+
|
| 193 |
+
best_model = None
|
| 194 |
+
for name, model in candidates:
|
| 195 |
+
if name == best_name:
|
| 196 |
+
best_model = model
|
| 197 |
+
break
|
| 198 |
|
| 199 |
# ── Feature importance ─────────────────────────
|
| 200 |
importance_data = _extract_importance(best_model, feature_cols)
|
|
|
|
| 229 |
json_results["_n_features"] = X.shape[1]
|
| 230 |
json_results["_n_folds"] = n_folds
|
| 231 |
json_results["_data_leakage_fix"] = "duration_sec and sample_rate removed from features (v2)"
|
| 232 |
+
json_results["_model_paths"] = all_model_paths
|
| 233 |
if importance_data:
|
| 234 |
json_results["_feature_importance"] = {
|
| 235 |
name: round(imp, 6) for name, imp in importance_data
|