@@ -346,10 +346,10 @@ def __init__(self, name: Optional[str],
346346 The metric that should be maximized or minimized in order to choose
347347 the best hyperparameter configuration.
348348
349- eval_final_performance [bool, default=True] :
349+ eval_final_performance:
350350 DEPRECATED! Use "use_test_set" instead!
351351
352- use_test_set [bool, default=True] :
352+ use_test_set:
353353 If the metrics should be calculated for the test set,
354354 otherwise the test set is seperated but not used.
355355
@@ -603,6 +603,11 @@ def input_data_sanity_checks(self, data, targets, **kwargs):
603603 "PHOTONAI erases every data item that has a Nan Target" .format (str (nr_of_nans )))
604604 self .X = self .X [~ nans_in_y ]
605605 self .y = self .y [~ nans_in_y ]
606+ new_kwargs = dict ()
607+ for name , element_list in kwargs .items ():
608+ new_kwargs [name ] = element_list [~ nans_in_y ]
609+ self .kwargs = new_kwargs
610+
606611 except Exception as e :
607612 # This is only for convenience so if it fails then never mind
608613 logger .error ("Removing Nans in target vector failed: " + str (e ))
@@ -637,7 +642,9 @@ def disable_multiprocessing_recursively(pipe):
637642 if hasattr (pipe , 'nr_of_processes' ):
638643 pipe .nr_of_processes = 1
639644 for child in pipe .elements :
640- if hasattr (child , 'base_element' ):
645+ if isinstance (child , Branch ):
646+ Hyperpipe .disable_multiprocessing_recursively (child )
647+ elif hasattr (child , 'base_element' ):
641648 Hyperpipe .disable_multiprocessing_recursively (child .base_element )
642649 elif isinstance (pipe , PhotonPipeline ):
643650 for name , child in pipe .named_steps .items ():
@@ -866,7 +873,8 @@ def _finalize_optimization(self):
866873 self .optimum_pipe .fit (self .data .X , self .data .y , ** self .data .kwargs )
867874
868875 # Before saving the optimum pipe, add preprocessing without multiprocessing
869- self .optimum_pipe .add_preprocessing (self .disable_multiprocessing_recursively (self .preprocessing ))
876+ self .disable_multiprocessing_recursively (self .preprocessing )
877+ self .optimum_pipe .add_preprocessing (self .preprocessing )
870878
871879 # Now truly set to no caching (including single_subject_caching)
872880 self .recursive_cache_folder_propagation (self .optimum_pipe , None , None )
@@ -939,11 +947,8 @@ def _prepare_pipeline(self):
939947 # ===================================================================
940948
941949 @staticmethod
942- def fit_outer_folds (outer_fold_computer , X , y , kwargs , cache_folder ):
943- try :
944- outer_fold_computer .fit (X , y , ** kwargs )
945- finally :
946- CacheManager .clear_cache_files (cache_folder )
950+ def fit_outer_folds (outer_fold_computer , X , y , kwargs ):
951+ outer_fold_computer .fit (X , y , ** kwargs )
947952 return
948953
949954 def fit (self , data : np .ndarray , targets : np .ndarray , ** kwargs ):
@@ -1038,8 +1043,7 @@ def fit(self, data: np.ndarray, targets: np.ndarray, **kwargs):
10381043 result = dask .delayed (Hyperpipe .fit_outer_folds )(outer_fold_computer ,
10391044 self .data .X ,
10401045 self .data .y ,
1041- self .data .kwargs ,
1042- self .cache_folder )
1046+ self .data .kwargs )
10431047 delayed_jobs .append (result )
10441048 else :
10451049 try :
@@ -1058,7 +1062,8 @@ def fit(self, data: np.ndarray, targets: np.ndarray, **kwargs):
10581062 # evaluate hyperparameter optimization results for best config
10591063 self ._finalize_optimization ()
10601064
1061- # clear complete cache ?
1065+ # clear complete cache ? use self.cache_folder to delete all subfolders within the parent cache folder
1066+ # directory
10621067 CacheManager .clear_cache_files (self .cache_folder , force_all = True )
10631068
10641069 ###############################################################################################
@@ -1247,15 +1252,6 @@ def get_permutation_feature_importances(self, **kwargs):
12471252 Returns mean of "importances_mean" and of "importances_std" of all outer folds.
12481253
12491254 Parameters:
1250- X_val:
1251- The array-like data with shape=[M, D],
1252- where M is the number of samples and D is the number
1253- of features. D must correspond to the number
1254- of trained dimensions of the fit method.
1255-
1256- y_val:
1257- The array-like true targets.
1258-
12591255 **kwargs:
12601256 Keyword arguments, passed to sklearn.permutation_importance.
12611257
0 commit comments