fix(ml): extract class labels from model when metadata is missing
The model info returned empty labels array because the pkl file has no metadata dict. Now extracts labels from model.classes_ or model.model.classes_ as fallback.
This commit is contained in:
parent
be09cef098
commit
f7b154f866
1 changed files with 10 additions and 1 deletions
|
|
@ -257,6 +257,15 @@ def load_model_from_local(model_path: str) -> tuple[Any, Dict[str, Any]]:
|
|||
model = model_data
|
||||
metadata = {}
|
||||
|
||||
# Extract labels from model if not in metadata
|
||||
labels = metadata.get("labels", [])
|
||||
if not labels:
|
||||
# Try to get class labels from the model itself
|
||||
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_]
|
||||
|
||||
# Build model info
|
||||
model_info = {
|
||||
"model_name": model_path.stem,
|
||||
|
|
@ -265,7 +274,7 @@ def load_model_from_local(model_path: str) -> tuple[Any, Dict[str, Any]]:
|
|||
"trained_at": metadata.get("trained_at", None),
|
||||
"dataset_version": metadata.get("dataset_version", None),
|
||||
"feature_engineering_enabled": metadata.get("feature_engineering_enabled", True),
|
||||
"labels": metadata.get("labels", []),
|
||||
"labels": labels,
|
||||
"per_class_metrics": metadata.get("per_class_metrics", [])
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue