|
42 | 42 | from ml_grid.util.global_params import global_parameters |
43 | 43 | from ml_grid.util.project_score_save import project_score_save_class |
44 | 44 | from ml_grid.util.validate_parameters import validate_parameters_helper |
45 | | -from sklearn.preprocessing import MinMaxScaler |
| 45 | +from sklearn.preprocessing import MinMaxScaler, StandardScaler |
46 | 46 | from ml_grid.util.bayes_utils import is_skopt_space |
47 | 47 | from skopt.space import Categorical |
48 | 48 |
|
@@ -176,8 +176,16 @@ def __init__( |
176 | 176 | max_param_space_iter_value = self.ml_grid_object_iter.local_param_dict.get("max_param_space_iter_value") |
177 | 177 |
|
178 | 178 | if "svc" in method_name.lower(): |
179 | | - self.X_train = scale_data(self.X_train) |
180 | | - self.X_test = scale_data(self.X_test) |
| 179 | + self.logger.info("Applying StandardScaler for SVC to prevent convergence issues.") |
| 180 | + scaler = StandardScaler() |
| 181 | + self.X_train = pd.DataFrame( |
| 182 | + scaler.fit_transform(self.X_train), |
| 183 | + columns=self.X_train.columns, |
| 184 | + index=self.X_train.index, |
| 185 | + ) |
| 186 | + self.X_test = pd.DataFrame( |
| 187 | + scaler.transform(self.X_test), columns=self.X_test.columns, index=self.X_test.index |
| 188 | + ) |
181 | 189 |
|
182 | 190 | # --- PERFORMANCE FIX for testing --- |
183 | 191 | # Use a much faster CV strategy when in test_mode. |
@@ -408,6 +416,11 @@ def __init__( |
408 | 416 | current_algorithm = search.run_search(X_train_reset, y_train_reset) |
409 | 417 |
|
410 | 418 | except Exception as e: |
| 419 | + if "dual coefficients or intercepts are not finite" in str(e): |
| 420 | + self.logger.warning(f"SVC failed to fit due to data issues: {e}. Returning default score.") |
| 421 | + self.grid_search_cross_validate_score_result = 0.5 |
| 422 | + return |
| 423 | + |
411 | 424 | # Log the error and re-raise it to stop the entire execution, |
412 | 425 | # allowing the main loop in main.py to handle it based on error_raise. |
413 | 426 | self.logger.error( |
|
0 commit comments