Update dataset_utils.py
Browse files- dataset_utils.py +11 -4
dataset_utils.py
CHANGED
@@ -142,14 +142,21 @@ def save_label_encoders(label_encoders):
|
|
142 |
def load_label_encoders():
|
143 |
"""
|
144 |
Loads a dictionary of label encoders from a pickle file.
|
|
|
145 |
|
146 |
Returns:
|
147 |
dict: Loaded dictionary of LabelEncoder objects.
|
148 |
"""
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
def get_num_labels(label_encoders):
|
155 |
"""
|
|
|
142 |
def load_label_encoders():
|
143 |
"""
|
144 |
Loads a dictionary of label encoders from a pickle file.
|
145 |
+
Handles scikit-learn version mismatches gracefully.
|
146 |
|
147 |
Returns:
|
148 |
dict: Loaded dictionary of LabelEncoder objects.
|
149 |
"""
|
150 |
+
try:
|
151 |
+
with open(LABEL_ENCODERS_PATH, "rb") as f:
|
152 |
+
label_encoders = pickle.load(f)
|
153 |
+
print(f"Label encoders loaded from {LABEL_ENCODERS_PATH}")
|
154 |
+
return label_encoders
|
155 |
+
except Exception as e:
|
156 |
+
print(f"Warning: Could not load label encoders from {LABEL_ENCODERS_PATH}: {str(e)}")
|
157 |
+
print("Creating new label encoders...")
|
158 |
+
# Create empty label encoders as fallback
|
159 |
+
return {col: LabelEncoder() for col in LABEL_COLUMNS}
|
160 |
|
161 |
def get_num_labels(label_encoders):
|
162 |
"""
|