Fix inference feature mismatch with training metadata

This commit is contained in:
Marko Djordjevic 2026-02-18 23:53:38 +01:00
parent 328476a581
commit 73c10a4156
3 changed files with 137 additions and 10 deletions

View file

@ -388,7 +388,28 @@ def train(
import joblib
output_model_path = Path(output_model_path)
output_model_path.parent.mkdir(parents=True, exist_ok=True)
joblib.dump(model, output_model_path)
labels = []
try:
if hasattr(model, "classes_"):
labels = [str(c) for c in model.classes_]
elif hasattr(model, "model") and hasattr(model.model, "classes_"):
labels = [str(c) for c in model.model.classes_]
except Exception:
labels = []
model_data = {
"model": model,
"metadata": {
"model_type": training_config.model_type,
"trained_at": datetime.utcnow().isoformat(),
"run_id": run_id,
"feature_columns": feature_cols,
"feature_engineering_enabled": config.stages.feature_engineering.enabled,
"labels": labels,
},
}
joblib.dump(model_data, output_model_path)
logger.info(f"Saved model to {output_model_path}")
# Update training run record in PostgreSQL