def __init__(self, estimator, param_grid, early_stopping=None, scoring=None, n_jobs=None, cv=5, refit=True, verbose=0, error_score="raise", return_train_score=False, local_dir="~/ray_results", max_iters=1, use_gpu=False, loggers=None, pipeline_auto_early_stop=True, stopper=None, time_budget_s=None, sk_n_jobs=None): if sk_n_jobs is not None: raise ValueError( "Tune-sklearn no longer supports nested parallelism " "with new versions of joblib/sklearn. Don't set 'sk_n_jobs'.") super(TuneGridSearchCV, self).__init__(estimator=estimator, early_stopping=early_stopping, scoring=scoring, n_jobs=n_jobs or -1, cv=cv, refit=refit, error_score=error_score, return_train_score=return_train_score, local_dir=local_dir, max_iters=max_iters, verbose=verbose, use_gpu=use_gpu, loggers=loggers, pipeline_auto_early_stop=pipeline_auto_early_stop, stopper=stopper, time_budget_s=time_budget_s) check_error_warm_start(self.early_stop_type, param_grid, estimator) _check_param_grid_tune_grid_search(param_grid) self.param_grid = param_grid
def __init__(self, estimator, param_grid, early_stopping=None, scoring=None, n_jobs=None, sk_n_jobs=-1, cv=5, refit=True, verbose=0, error_score="raise", return_train_score=False, local_dir="~/ray_results", max_iters=1, use_gpu=False, loggers=None, pipeline_auto_early_stop=True): super(TuneGridSearchCV, self).__init__( estimator=estimator, early_stopping=early_stopping, scoring=scoring, n_jobs=n_jobs or -1, sk_n_jobs=sk_n_jobs, cv=cv, refit=refit, error_score=error_score, return_train_score=return_train_score, local_dir=local_dir, max_iters=max_iters, verbose=verbose, use_gpu=use_gpu, loggers=loggers, pipeline_auto_early_stop=pipeline_auto_early_stop) check_error_warm_start(self.early_stop_type, param_grid, estimator) _check_param_grid(param_grid) self.param_grid = param_grid
def __init__(self, estimator, param_distributions, early_stopping=None, n_trials=10, scoring=None, n_jobs=None, refit=True, cv=None, verbose=0, random_state=None, error_score=np.nan, return_train_score=False, local_dir="~/ray_results", max_iters=1, search_optimization="random", use_gpu=False, loggers=None, pipeline_auto_early_stop=True, stopper=None, time_budget_s=None, sk_n_jobs=None, **search_kwargs): if sk_n_jobs is not None: raise ValueError( "Tune-sklearn no longer supports nested parallelism " "with new versions of joblib/sklearn. Don't set 'sk_n_jobs'.") search_optimization = search_optimization.lower() available_optimizations = [ "random", "bayesian", # scikit-optimize/SkOpt "bohb", "hyperopt", "optuna", ] if (search_optimization not in available_optimizations): raise ValueError("Search optimization must be one of " f"{', '.join(available_optimizations)}") self._try_import_required_libraries(search_optimization) if isinstance(param_distributions, list): if search_optimization != "random": raise ValueError("list of dictionaries for parameters " "is not supported for non-random search") if isinstance(param_distributions, dict): check_param_distributions = [param_distributions] else: check_param_distributions = param_distributions can_use_param_distributions = False from ray.tune.schedulers import HyperBandForBOHB if search_optimization == "bohb": import ConfigSpace as CS can_use_param_distributions = isinstance(check_param_distributions, CS.ConfigurationSpace) if early_stopping is False: raise ValueError( "early_stopping must not be False when using BOHB") elif not isinstance(early_stopping, HyperBandForBOHB): if early_stopping != "HyperBandForBOHB": warnings.warn("Ignoring early_stopping value, " "as BOHB requires HyperBandForBOHB " "as the EarlyStopping scheduler") early_stopping = "HyperBandForBOHB" elif early_stopping == "HyperBandForBOHB" or isinstance( early_stopping, HyperBandForBOHB): raise ValueError("search_optimization must be set to 'BOHB' " "if early_stopping is set to HyperBandForBOHB") if not can_use_param_distributions: for p in check_param_distributions: for dist in p.values(): _check_distribution(dist, search_optimization) super(TuneSearchCV, self).__init__(estimator=estimator, early_stopping=early_stopping, scoring=scoring, n_jobs=n_jobs or -1, cv=cv, verbose=verbose, refit=refit, error_score=error_score, return_train_score=return_train_score, local_dir=local_dir, max_iters=max_iters, use_gpu=use_gpu, loggers=loggers, pipeline_auto_early_stop=pipeline_auto_early_stop, stopper=stopper, time_budget_s=time_budget_s) check_error_warm_start(self.early_stop_type, param_distributions, estimator) self.param_distributions = param_distributions self.n_trials = n_trials self.random_state = random_state if isinstance(random_state, np.random.RandomState): # For compatibility with all search algorithms we just # sample a seed from the random state self.seed = random_state.randint(2**32 - 1) else: self.seed = random_state if search_optimization == "random": if search_kwargs: raise ValueError("Random search does not support " f"extra args: {search_kwargs}") self.search_optimization = search_optimization self.search_kwargs = search_kwargs
def __init__(self, estimator, param_distributions, early_stopping=None, n_trials=10, scoring=None, n_jobs=None, sk_n_jobs=-1, refit=True, cv=None, verbose=0, random_state=None, error_score=np.nan, return_train_score=False, local_dir="~/ray_results", max_iters=1, search_optimization="random", use_gpu=False, loggers=None, pipeline_auto_early_stop=True, **search_kwargs): search_optimization = search_optimization.lower() available_optimizations = [ "random", "bayesian", # scikit-optimize/SkOpt "bohb", "hyperopt", # "optuna", # optuna is not yet in stable ray.tune ] if (search_optimization not in available_optimizations): raise ValueError("Search optimization must be one of " f"{', '.join(available_optimizations)}") if (search_optimization != "random" and random_state is not None): warnings.warn( "random state is ignored when not using Random optimization") self._try_import_required_libraries(search_optimization) if isinstance(param_distributions, list): if search_optimization != "random": raise ValueError("list of dictionaries for parameters " "is not supported for non-random search") if isinstance(param_distributions, dict): check_param_distributions = [param_distributions] else: check_param_distributions = param_distributions can_use_param_distributions = False if search_optimization == "bohb": import ConfigSpace as CS can_use_param_distributions = isinstance(check_param_distributions, CS.ConfigurationSpace) if not can_use_param_distributions: for p in check_param_distributions: for dist in p.values(): _check_distribution(dist, search_optimization) super(TuneSearchCV, self).__init__(estimator=estimator, early_stopping=early_stopping, scoring=scoring, n_jobs=n_jobs or -1, sk_n_jobs=sk_n_jobs, cv=cv, verbose=verbose, refit=refit, error_score=error_score, return_train_score=return_train_score, local_dir=local_dir, max_iters=max_iters, use_gpu=use_gpu, loggers=loggers, pipeline_auto_early_stop=pipeline_auto_early_stop) if search_optimization == "bohb": from ray.tune.schedulers import HyperBandForBOHB if not isinstance(early_stopping, HyperBandForBOHB): early_stopping = HyperBandForBOHB(metric=self._metric_name, mode="max", max_t=max_iters) check_error_warm_start(self.early_stop_type, param_distributions, estimator) self.param_distributions = param_distributions self.num_samples = n_trials if search_optimization == "random": self.random_state = random_state if search_kwargs: raise ValueError("Random search does not support " f"extra args: {search_kwargs}") self.search_optimization = search_optimization self.search_kwargs = search_kwargs