def validate_parameters(self): """Ensure the provided parameters are valid and properly formatted""" #################### metrics_params/metrics #################### if (self.metrics is not None) and ("metrics" in self.metrics_params.keys()): raise ValueError( "`metrics` may be provided as a kwarg, or as a `metrics_params` key, but NOT BOTH. Received: " + f"\n `metrics`={self.metrics}\n `metrics_params`={self.metrics_params}" ) else: _metrics_alias = "metrics" if self.metrics is None: try: self.metrics = self.metrics_params["metrics"] except KeyError: self.metrics = self.metrics_params["metrics_map"] _metrics_alias = "metrics_map" self.metrics = format_metrics(self.metrics) self.metrics_params = { **{ _metrics_alias: self.metrics }, **self.metrics_params }
def test_get_formatted_target_metric_value_error(target_metric): with pytest.raises(ValueError): get_formatted_target_metric(target_metric, format_metrics(["roc_auc_score"]))
def validate_parameters(self): """Ensure the provided parameters are valid and properly formatted""" #################### results_path #################### if self.results_path is None: G.warn( "Received results_path=None. Results will not be stored at all." ) elif isinstance(self.results_path, str): if not self.results_path.endswith(ASSETS_DIRNAME): self.results_path = os.path.join(self.results_path, ASSETS_DIRNAME) self.result_paths["root"] = self.results_path if not os.path.exists(self.results_path): make_dirs(self.results_path, exist_ok=True) else: raise TypeError( f"results_path must be None or str, not {self.results_path}") #################### target_column #################### if isinstance(self.target_column, str): self.target_column = [self.target_column] #################### file_blacklist #################### self.file_blacklist = validate_file_blacklist(self.file_blacklist) if self.results_path is None: self.file_blacklist = "ALL" #################### Train/Test Datasets #################### if isinstance(self.train_dataset, str): self.train_dataset = pd.read_csv(self.train_dataset) if isinstance(self.test_dataset, str): self.test_dataset = pd.read_csv(self.test_dataset) #################### metrics_params/metrics #################### if (self.metrics is not None) and ("metrics" in self.metrics_params.keys()): raise ValueError( "`metrics` may be provided as a kwarg, or as a `metrics_params` key, but NOT BOTH. Received: " + f"\n `metrics`={self.metrics}\n `metrics_params`={self.metrics_params}" ) else: _metrics_alias = "metrics" if self.metrics is None: try: self.metrics = self.metrics_params["metrics"] except KeyError: self.metrics = self.metrics_params["metrics_map"] _metrics_alias = "metrics_map" self.metrics = format_metrics(self.metrics) self.metrics_params = { **{ _metrics_alias: self.metrics }, **self.metrics_params } #################### cv_type #################### if isinstance(self.cv_type, str): try: self.cv_type = sk_cv.__getattribute__(self.cv_type) except AttributeError: raise AttributeError( f"'{self.cv_type}' not in `sklearn.model_selection._split`" ) #################### to_csv_params #################### self.to_csv_params = { k: v for k, v in self.to_csv_params.items() if k != "path_or_buf" } #################### cross_experiment_params #################### self.cross_experiment_params = dict( cv_type=self.cv_type, runs=self.runs, global_random_seed=self.global_random_seed, random_seeds=self.random_seeds, random_seed_bounds=self.random_seed_bounds, ) #################### experiment_callbacks #################### if not isinstance(self.experiment_callbacks, list): self.experiment_callbacks = [self.experiment_callbacks] for cb in self.experiment_callbacks: if not isclass(cb): raise TypeError( f"experiment_callbacks must be classes, not {type(cb)}: {cb}" ) if cb.__name__ != "LambdaCallback": raise ValueError( f"experiment_callbacks must be LambdaCallback instances, not {cb}" )