@@ -172,22 +172,33 @@ def __init__(
172172 ) # hard limit on param space exploration
173173
174174 # Allow local override for max_param_space_iter_value
175- if self .ml_grid_object_iter .local_param_dict .get ("max_param_space_iter_value" ) is not None :
176- max_param_space_iter_value = self .ml_grid_object_iter .local_param_dict .get ("max_param_space_iter_value" )
175+ if (
176+ self .ml_grid_object_iter .local_param_dict .get ("max_param_space_iter_value" )
177+ is not None
178+ ):
179+ max_param_space_iter_value = self .ml_grid_object_iter .local_param_dict .get (
180+ "max_param_space_iter_value"
181+ )
177182
178183 if "svc" in method_name .lower ():
179- self .logger .info ("Applying StandardScaler for SVC to prevent convergence issues." )
184+ self .logger .info (
185+ "Applying StandardScaler for SVC to prevent convergence issues."
186+ )
180187 scaler = StandardScaler ()
181188 self .X_train = pd .DataFrame (
182189 scaler .fit_transform (self .X_train ),
183190 columns = self .X_train .columns ,
184191 index = self .X_train .index ,
185192 )
186193 self .X_test = pd .DataFrame (
187- scaler .transform (self .X_test ), columns = self .X_test .columns , index = self .X_test .index
194+ scaler .transform (self .X_test ),
195+ columns = self .X_test .columns ,
196+ index = self .X_test .index ,
188197 )
189198 self .X_test_orig = pd .DataFrame (
190- scaler .transform (self .X_test_orig ), columns = self .X_test_orig .columns , index = self .X_test_orig .index
199+ scaler .transform (self .X_test_orig ),
200+ columns = self .X_test_orig .columns ,
201+ index = self .X_test_orig .index ,
191202 )
192203
193204 # --- PERFORMANCE FIX for testing ---
@@ -303,17 +314,23 @@ def __init__(
303314 n_iter_v = 2
304315 n_iter_v = int (n_iter_v )
305316 except (ValueError , TypeError ):
306- self .logger .warning ("Invalid or missing n_iter in global_params. Defaulting to 2." )
317+ self .logger .warning (
318+ "Invalid or missing n_iter in global_params. Defaulting to 2."
319+ )
307320 n_iter_v = 2
308321
309322 # Allow local override from run_params/local_param_dict
310323 local_n_iter = self .ml_grid_object_iter .local_param_dict .get ("n_iter" )
311324 if local_n_iter is not None :
312325 try :
313326 n_iter_v = int (local_n_iter )
314- self .logger .info (f"Overriding global n_iter with local value: { n_iter_v } " )
327+ self .logger .info (
328+ f"Overriding global n_iter with local value: { n_iter_v } "
329+ )
315330 except (ValueError , TypeError ):
316- self .logger .warning (f"Invalid local n_iter value: { local_n_iter } . Ignoring override." )
331+ self .logger .warning (
332+ f"Invalid local n_iter value: { local_n_iter } . Ignoring override."
333+ )
317334
318335 if max_param_space_iter_value is not None :
319336 if n_iter_v > max_param_space_iter_value :
@@ -420,7 +437,9 @@ def __init__(
420437
421438 except Exception as e :
422439 if "dual coefficients or intercepts are not finite" in str (e ):
423- self .logger .warning (f"SVC failed to fit due to data issues: { e } . Returning default score." )
440+ self .logger .warning (
441+ f"SVC failed to fit due to data issues: { e } . Returning default score."
442+ )
424443 self .grid_search_cross_validate_score_result = 0.5
425444 return
426445
@@ -476,9 +495,15 @@ def __init__(
476495 # Define default scores (e.g., mean score of 0.5 for binary classification)
477496 # Default scores if cross-validation fails
478497 default_scores = {
479- "test_accuracy" : np .array ([0.5 ]), # Default to random classifier performance
480- "test_f1" : np .array ([0.5 ]), # Default F1 score (again, 0.5 for random classification)
481- "test_auc" : np .array ([0.5 ]), # Default ROC AUC score (0.5 for random classifier)
498+ "test_accuracy" : np .array (
499+ [0.5 ]
500+ ), # Default to random classifier performance
501+ "test_f1" : np .array (
502+ [0.5 ]
503+ ), # Default F1 score (again, 0.5 for random classification)
504+ "test_auc" : np .array (
505+ [0.5 ]
506+ ), # Default ROC AUC score (0.5 for random classifier)
482507 "fit_time" : np .array ([0 ]), # No fitting time if the model fails
483508 "score_time" : np .array ([0 ]), # No scoring time if the model fails
484509 "train_score" : np .array ([0.5 ]), # Default train score
@@ -535,11 +560,15 @@ def __init__(
535560 )
536561
537562 if force_second_cv :
538- self .logger .info ("force_second_cv is True. Skipping cached result extraction to run fresh cross-validation." )
563+ self .logger .info (
564+ "force_second_cv is True. Skipping cached result extraction to run fresh cross-validation."
565+ )
539566
540567 # Check if we can reuse results from HyperparameterSearch
541- if not force_second_cv and hasattr (current_algorithm , "cv_results_" ) and hasattr (
542- current_algorithm , "best_index_"
568+ if (
569+ not force_second_cv
570+ and hasattr (current_algorithm , "cv_results_" )
571+ and hasattr (current_algorithm , "best_index_" )
543572 ):
544573 try :
545574 self .logger .info (
@@ -553,22 +582,33 @@ def __init__(
553582 # Extract fit and score times
554583 if "split0_fit_time" in results :
555584 temp_scores ["fit_time" ] = np .array (
556- [results [f"split{ k } _fit_time" ][index ] for k in range (n_splits )]
585+ [
586+ results [f"split{ k } _fit_time" ][index ]
587+ for k in range (n_splits )
588+ ]
557589 )
558590 else :
559591 # Fallback: Use mean time repeated if split times are missing (e.g. BayesSearchCV)
560- temp_scores ["fit_time" ] = np .full (n_splits , results ["mean_fit_time" ][index ])
592+ temp_scores ["fit_time" ] = np .full (
593+ n_splits , results ["mean_fit_time" ][index ]
594+ )
561595
562596 if "split0_score_time" in results :
563597 temp_scores ["score_time" ] = np .array (
564- [results [f"split{ k } _score_time" ][index ] for k in range (n_splits )]
598+ [
599+ results [f"split{ k } _score_time" ][index ]
600+ for k in range (n_splits )
601+ ]
565602 )
566603 else :
567604 # Fallback: Use mean score time.
568605 # We use .get() with a default that is safe to index into if the key is missing.
569606 # If 'mean_score_time' is missing, we default to a list of 0s large enough to cover 'index'.
570607 default_times = np .zeros (index + 1 )
571- temp_scores ["score_time" ] = np .full (n_splits , results .get ("mean_score_time" , default_times )[index ])
608+ temp_scores ["score_time" ] = np .full (
609+ n_splits ,
610+ results .get ("mean_score_time" , default_times )[index ],
611+ )
572612
573613 # Extract metric scores
574614 for metric in self .metric_list :
@@ -582,7 +622,9 @@ def __init__(
582622 )
583623 # Train scores (if available)
584624 train_key = f"train_{ metric } "
585- train_col = f"split0_train_{ metric } " # Check existence on first split
625+ train_col = (
626+ f"split0_train_{ metric } " # Check existence on first split
627+ )
586628 if train_col in results :
587629 temp_scores [train_key ] = np .array (
588630 [
@@ -592,7 +634,9 @@ def __init__(
592634 )
593635 scores = temp_scores
594636 except Exception as e :
595- self .logger .warning (f"Could not extract cached CV results: { e } . Falling back to standard CV." )
637+ self .logger .warning (
638+ f"Could not extract cached CV results: { e } . Falling back to standard CV."
639+ )
596640 scores = None
597641
598642 if scores is None :
@@ -628,7 +672,11 @@ def __init__(
628672 # This is done AFTER fitting and before cross-validation.
629673 if isinstance (
630674 current_algorithm ,
631- (KerasClassifier , KerasClassifierClass , NeuralNetworkClassifier ),
675+ (
676+ KerasClassifier ,
677+ KerasClassifierClass ,
678+ NeuralNetworkClassifier ,
679+ ),
632680 ):
633681 try :
634682 self .logger .debug (
@@ -637,7 +685,9 @@ def __init__(
637685 n_features = self .X_train .shape [1 ]
638686 # Define an input signature that allows for variable batch size.
639687 input_signature = [
640- tf .TensorSpec (shape = (None , n_features ), dtype = tf .float32 )
688+ tf .TensorSpec (
689+ shape = (None , n_features ), dtype = tf .float32
690+ )
641691 ]
642692 # Access the underlying Keras model via .model_
643693 current_algorithm .model_ .predict .get_concrete_function (
0 commit comments