Update model/train.py
Browse files- model/train.py +8 -5
model/train.py
CHANGED
@@ -1150,7 +1150,14 @@ class EnhancedModelTrainer:
|
|
1150 |
|
1151 |
# Save individual components for backward compatibility
|
1152 |
try:
|
1153 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1154 |
if 'model' in model.named_steps:
|
1155 |
joblib.dump(model.named_steps['model'], self.model_path)
|
1156 |
logger.info(f"β
Saved model component to {self.model_path}")
|
@@ -1168,10 +1175,6 @@ class EnhancedModelTrainer:
|
|
1168 |
}
|
1169 |
joblib.dump(enhanced_ref, self.vectorizer_path)
|
1170 |
logger.info(f"β
Saved enhanced features reference to {self.vectorizer_path}")
|
1171 |
-
elif model_name == 'ensemble':
|
1172 |
-
# Handle ensemble model saving
|
1173 |
-
joblib.dump(model, self.model_path)
|
1174 |
-
logger.info(f"β
Saved ensemble model to {self.model_path}")
|
1175 |
|
1176 |
except Exception as e:
|
1177 |
logger.warning(f"Could not save individual components: {e}")
|
|
|
1150 |
|
1151 |
# Save individual components for backward compatibility
|
1152 |
try:
|
1153 |
+
if model_name == 'ensemble':
|
1154 |
+
# Handle ensemble model saving - ensemble has different structure
|
1155 |
+
joblib.dump(model, self.model_path)
|
1156 |
+
logger.info(f"β
Saved ensemble model to {self.model_path}")
|
1157 |
+
|
1158 |
+
# Don't try to extract individual components from ensemble
|
1159 |
+
|
1160 |
+
elif hasattr(model, 'named_steps'):
|
1161 |
if 'model' in model.named_steps:
|
1162 |
joblib.dump(model.named_steps['model'], self.model_path)
|
1163 |
logger.info(f"β
Saved model component to {self.model_path}")
|
|
|
1175 |
}
|
1176 |
joblib.dump(enhanced_ref, self.vectorizer_path)
|
1177 |
logger.info(f"β
Saved enhanced features reference to {self.vectorizer_path}")
|
|
|
|
|
|
|
|
|
1178 |
|
1179 |
except Exception as e:
|
1180 |
logger.warning(f"Could not save individual components: {e}")
|