Example #1
0
 def __init__(self,
              estimator,
              param_grid,
              scoring=None,
              n_jobs=None,
              refit=True,
              verbose=0,
              cv=None,
              pre_dispatch='2*n_jobs',
              random_state=None,
              error_score=np.nan,
              return_train_score=True,
              max_budget='auto',
              budget_on='n_samples',
              ratio=3,
              r_min='auto',
              aggressive_elimination=False,
              force_exhaust_budget=False):
     super().__init__(estimator,
                      scoring=scoring,
                      n_jobs=n_jobs,
                      verbose=verbose,
                      cv=cv,
                      pre_dispatch=pre_dispatch,
                      random_state=random_state,
                      error_score=error_score,
                      return_train_score=return_train_score,
                      max_budget=max_budget,
                      budget_on=budget_on,
                      ratio=ratio,
                      r_min=r_min,
                      aggressive_elimination=aggressive_elimination,
                      force_exhaust_budget=force_exhaust_budget)
     self.param_grid = param_grid
     _check_param_grid(self.param_grid)
Example #2
0
    def __init__(self,
                 estimator,
                 param_grid,
                 *,
                 scoring=None,
                 n_jobs=None,
                 iid='deprecated',
                 refit=True,
                 cv=None,
                 verbose=0,
                 pre_dispatch='2*n_jobs',
                 error_score=np.nan,
                 return_train_score=False,
                 active_trainer: trainer.Trainer = None):
        super().__init__(estimator=estimator,
                         param_grid=param_grid,
                         scoring=scoring,
                         n_jobs=n_jobs,
                         iid=iid,
                         refit=refit,
                         cv=cv,
                         verbose=verbose,
                         pre_dispatch=pre_dispatch,
                         error_score=error_score,
                         return_train_score=return_train_score)

        self.param_grid = param_grid
        self.__active_trainer = active_trainer
        _check_param_grid(param_grid)
Example #3
0
 def __init__(self,
              estimator,
              param_grid,
              scoring=None,
              fit_params=None,
              n_jobs=1,
              iid=True,
              refit=True,
              cv=None,
              verbose=0,
              pre_dispatch='2*n_jobs',
              error_score='raise',
              return_train_score=True):
     super(GridSearchCVfastr,
           self).__init__(estimator=estimator,
                          scoring=scoring,
                          fit_params=fit_params,
                          n_jobs=n_jobs,
                          iid=iid,
                          refit=refit,
                          cv=cv,
                          verbose=verbose,
                          pre_dispatch=pre_dispatch,
                          error_score=error_score,
                          return_train_score=return_train_score)
     self.param_grid = param_grid
     _check_param_grid(param_grid)
Example #4
0
 def __init__(self,
              estimator,
              param_grid,
              scoring=None,
              fit_params=None,
              n_jobs=1,
              iid=True,
              refit=True,
              cv=None,
              verbose=3,
              pre_dispatch='2*n_jobs',
              error_score='raise',
              return_train_score="warn",
              logger_level='notset',
              parallel_backend='threading'):
     super(GridSearchCVMultisignal,
           self).__init__(estimator=estimator,
                          scoring=scoring,
                          fit_params=fit_params,
                          n_jobs=n_jobs,
                          iid=iid,
                          refit=refit,
                          cv=cv,
                          verbose=verbose,
                          pre_dispatch=pre_dispatch,
                          error_score=error_score,
                          return_train_score=return_train_score,
                          logger_level=logger_level,
                          parallel_backend=parallel_backend)
     self.param_grid = param_grid
     _check_param_grid(param_grid)
Example #5
0
 def __init__(self,
              estimator,
              param_grid,
              *,
              online_train_val_split=False,
              scoring=None,
              n_jobs=None,
              refit=True,
              cv=None,
              verbose=0,
              pre_dispatch='2*n_jobs',
              error_score=np.nan,
              return_train_score=False):
     super().__init__(estimator=estimator,
                      scoring=scoring,
                      online_train_val_split=online_train_val_split,
                      n_jobs=n_jobs,
                      refit=refit,
                      cv=cv,
                      verbose=verbose,
                      pre_dispatch=pre_dispatch,
                      error_score=error_score,
                      return_train_score=return_train_score)
     self.param_grid = param_grid
     _check_param_grid(param_grid)
Example #6
0
    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,
                 max_iters=10,
                 use_gpu=False):
        super(TuneGridSearchCV,
              self).__init__(estimator=estimator,
                             early_stopping=early_stopping,
                             scoring=scoring,
                             n_jobs=n_jobs,
                             cv=cv,
                             refit=refit,
                             error_score=error_score,
                             return_train_score=return_train_score,
                             max_iters=max_iters,
                             verbose=verbose,
                             use_gpu=use_gpu)

        _check_param_grid(param_grid)
        self.param_grid = param_grid
    def __init__(self,
                 sc,
                 estimator,
                 param_grid,
                 scoring=None,
                 fit_params=None,
                 n_jobs=1,
                 iid=True,
                 refit=True,
                 cv=3,
                 verbose=0,
                 pre_dispatch='2*n_jobs',
                 error_score='raise',
                 return_train_score=True):
        super(GridSearchCV,
              self).__init__(estimator=estimator,
                             scoring=scoring,
                             n_jobs=n_jobs,
                             iid=iid,
                             refit=refit,
                             cv=cv,
                             verbose=verbose,
                             pre_dispatch=pre_dispatch,
                             error_score=error_score,
                             return_train_score=return_train_score)

        self.fit_params = fit_params if fit_params is not None else {}

        self.sc = sc
        self.param_grid = param_grid

        self.cv_results_ = None
        _check_param_grid(param_grid)
Example #8
0
 def __init__(
     self,
     estimator,
     param_grid,
     *,
     scoring=None,
     n_jobs=None,
     refit=True,
     cv=None,
     verbose=0,
     pre_dispatch="2*n_jobs",
     error_score=np.nan,
     return_train_score=False,
 ):
     super().__init__(
         estimator=estimator,
         scoring=scoring,
         n_jobs=n_jobs,
         refit=refit,
         cv=cv,
         verbose=verbose,
         pre_dispatch=pre_dispatch,
         error_score=error_score,
         return_train_score=return_train_score,
     )
     self.param_grid = param2grid(param_grid)
     _check_param_grid(param_grid)
Example #9
0
    def __init__(
        self,
        param_grid="tiny",
        scoring=None,
        iid=True,
        cv=None,
        refit=True,
        verbose=0,
        return_train_score=True,
    ):

        self.param_grid = param_grid
        if isinstance(self.param_grid, str):
            if self.param_grid == "tiny":
                self.param_grid = load_grid_tiny()
            elif self.param_grid == "small":
                self.param_grid = load_grid_small()
            elif self.param_grid == "full":
                self.param_grid = load_grid_full()
            else:
                raise ValueError("Unknown param grid %r" % self.param_grid)
        _check_param_grid(self.param_grid)
        _validate_param_grid(self.param_grid)

        self.scoring = scoring
        self.cv = 5 if cv is None else cv
        if isinstance(self.cv, ShuffleSplit) or isinstance(
                self.cv, StratifiedShuffleSplit):
            raise ValueError(
                "ShuffleSplit and StratifiedShuffleSplit are not supported at the moment. Please see the documentation for more info"
            )
        self.refit = refit
        self.verbose = verbose
        self.return_train_score = return_train_score
        self.iid = iid
Example #10
0
    def __init__(
        self,
        estimator,
        param_grid,
        scheduler=None,
        scoring=None,
        n_jobs=None,
        cv=5,
        refit=True,
        verbose=0,
        error_score='raise',
        return_train_score=False,
        early_stopping=False,
        iters=1,
    ):
        super(TuneGridSearchCV, self).__init__(
            estimator=estimator,
            scheduler=scheduler,
            scoring=scoring,
            n_jobs=n_jobs,
            cv=cv,
            refit=refit,
            error_score=error_score,
            return_train_score=return_train_score,
            early_stopping=early_stopping,
            iters=iters,
        )

        _check_param_grid(param_grid)
        self.param_grid = param_grid
Example #11
0
 def __init__(
     self,
     forecaster,
     cv,
     param_grid,
     scoring=None,
     n_jobs=None,
     refit=True,
     verbose=0,
     pre_dispatch="2*n_jobs",
     error_score=np.nan,
     return_train_score=False,
 ):
     super(ForecastingGridSearchCV, self).__init__(
         forecaster=forecaster,
         scoring=scoring,
         n_jobs=n_jobs,
         refit=refit,
         cv=cv,
         verbose=verbose,
         pre_dispatch=pre_dispatch,
         error_score=error_score,
         return_train_score=return_train_score,
     )
     self.param_grid = param_grid
     _check_param_grid(param_grid)
    def __init__(self,
                 estimator,
                 param_grid,
                 scoring=None,
                 iid=True,
                 refit=True,
                 cv=None,
                 error_score='raise',
                 return_train_score=True,
                 scheduler=None,
                 n_jobs=-1,
                 cache_cv=True):
        super(GridSearchCV,
              self).__init__(estimator=estimator,
                             scoring=scoring,
                             iid=iid,
                             refit=refit,
                             cv=cv,
                             error_score=error_score,
                             return_train_score=return_train_score,
                             scheduler=scheduler,
                             n_jobs=n_jobs,
                             cache_cv=cache_cv)

        _check_param_grid(param_grid)
        self.param_grid = param_grid
Example #13
0
 def __init__(self,
              estimator,
              param_grid,
              scoring=None,
              fit_params=None,
              n_jobs=None,
              iid='warn',
              refit=True,
              cv='warn',
              verbose=0,
              pre_dispatch='2*n_jobs',
              error_score='raise-deprecating',
              return_train_score=False):
     super().__init__(estimator=estimator,
                      scoring=scoring,
                      fit_params=fit_params,
                      n_jobs=n_jobs,
                      iid=iid,
                      refit=refit,
                      cv=cv,
                      verbose=verbose,
                      pre_dispatch=pre_dispatch,
                      error_score=error_score,
                      return_train_score=return_train_score)
     self.param_grid = param_grid
     _check_param_grid(param_grid)
Example #14
0
 def __init__(self, sc, estimator, param_grid, *args, **kwargs):
     self.sc = sc
     self.param_grid = param_grid
     self.estimator = estimator
     _check_param_grid(param_grid)
     super(SparkBaseSearchCV, self).__init__(estimator=self.estimator,
                                             *args,
                                             **kwargs)
Example #15
0
def _normalize_param_grid(param_grid):
    """Normalize the parameter grid to use with
    parametrized estimators."""
    _check_param_grid(param_grid)
    normalized_param_grid = param_grid.copy()
    est_name = list(set([param.split('__')[0] for param in param_grid.keys()]))
    normalized_param_grid.update({'est_name': est_name})
    return normalized_param_grid
Example #16
0
    def fit(self, cvs, groups=None, **fit_params):

        self.best_estimator_ = None
        self.best_mem_score_ = float("-inf")
        self.best_mem_params_ = None
        for possible_params in self.possible_params:
            _check_param_grid(possible_params)
            self._fit(cvs, possible_params)
Example #17
0
    def __init__(self, estimator, param_grid, scoring=None, iid=True,
                 refit=True, cv=None, error_score='raise',
                 return_train_score=True, get=None):
        super(DaskGridSearchCV, self).__init__(estimator=estimator,
                scoring=scoring, iid=iid, refit=refit, cv=cv,
                error_score=error_score, return_train_score=return_train_score,
                get=get)

        _check_param_grid(param_grid)
        self.param_grid = param_grid
Example #18
0
    def __init__(self, sc, estimator, param_grid, scoring=None, iid='warn',
                 refit=True, cv=None, verbose=0,
                 error_score='raise-deprecating', return_train_score=False):

        super(GridSearchCV, self).__init__(estimator, scoring, iid, refit, cv,
              verbose, error_score, return_train_score)

        self.sc = sc
        self.param_grid = param_grid
        _check_param_grid(param_grid)
Example #19
0
    def __init__(self, estimator, param_grid, scoring=None, iid=True,
                 refit=True, cv=None, error_score='raise',
                 return_train_score=True, scheduler=None, n_jobs=-1,
                 cache_cv=True):
        super(GridSearchCV, self).__init__(estimator=estimator,
                scoring=scoring, iid=iid, refit=refit, cv=cv,
                error_score=error_score, return_train_score=return_train_score,
                scheduler=scheduler, n_jobs=n_jobs, cache_cv=cache_cv)

        _check_param_grid(param_grid)
        self.param_grid = param_grid
Example #20
0
 def __init__(self, estimator, param_dict, scoring=None, n_jobs=1, cv=None, cv_exclude_first=0.0, verbose=0):
     self.estimator = estimator
     self.param_dict = param_dict
     self.scoring = scoring
     self.n_jobs = n_jobs
     self.cv = cv
     self.cv_exclude_first = cv_exclude_first
     self.verbose = verbose
     self.bayesian_optimizer = BayesianOptimization(self._evaluate, self.param_dict, verbose=verbose)
     self.scorer_ = check_scoring(self.estimator, scoring=self.scoring)
     _check_param_grid(self.param_dict)
Example #21
0
 def fit(self, X, y=None):
     self.best_estimator_ = None
     self.best_mem_score_ = float("-inf")
     self.best_mem_params_ = None
     for possible_params in self.possible_params:
         _check_param_grid(possible_params)
         self._fit(X, y, possible_params)
     if self.refit:
         self.best_estimator_ = clone(self.estimator)
         self.best_estimator_.set_params(**self.best_mem_params_)
         self.best_estimator_.fit(X, y)
Example #22
0
 def __init__(self, estimator, param_grid, scoring=None,
              n_jobs=None, refit=True, verbose=0, cv=None,
              pre_dispatch='2*n_jobs', random_state=None,
              error_score=np.nan, return_train_score=True):
     super().__init__(estimator, scoring=scoring,
                      n_jobs=n_jobs, verbose=verbose, cv=cv,
                      pre_dispatch=pre_dispatch,
                      random_state=random_state, error_score=error_score,
                      return_train_score=return_train_score)
     self.param_grid = param_grid
     _check_param_grid(self.param_grid)
 def fit(self, X, y):
     self.best_estimator_ = None
     self.best_mem_score_ = float("-inf")
     self.best_mem_params_ = None
     _check_param_grid(self.params)
     self._fit(X, y, self.params)
     if self.refit:
         self.best_estimator_ = clone(self.estimator)
         self.best_estimator_.set_params(**self.best_mem_params_)
         if self.fit_params is not None:
             self.best_estimator_.fit(X, y, **self.fit_params)
         else:
             self.best_estimator_.fit(X, y)
Example #24
0
 def __init__(self, estimator, param_grid, n_iter, n_initial_points, scoring=None, fit_params=None,
              n_jobs=1, iid=True, refit=True, cv=None, verbose=0,
              pre_dispatch='2*n_jobs', error_score='raise'):
     #assert(n_jobs == 1)
     super(BayesianOptimizationSearchCV, self).__init__(
         estimator=estimator, scoring=scoring, fit_params=fit_params,
         n_jobs=n_jobs, iid=iid, refit=refit, cv=cv, verbose=verbose,
         pre_dispatch=pre_dispatch, error_score=error_score)
     self.param_grid = param_grid
     assert(n_iter >= 0)
     self.n_iter = n_iter
     assert(n_initial_points > 0)
     self.n_initial_points = n_initial_points
     _search._check_param_grid(param_grid)
Example #25
0
    def __init__(self, sc, estimator, param_grid, scoring=None, fit_params=None,
                 n_jobs=1, iid=True, refit=True, cv=3, verbose=0,
                 pre_dispatch='2*n_jobs', error_score='raise', return_train_score=True):
        super(GridSearchCV, self).__init__(
            estimator=estimator, scoring=scoring, n_jobs=n_jobs, iid=iid,
            refit=refit, cv=cv, verbose=verbose, pre_dispatch=pre_dispatch, error_score=error_score,
            return_train_score=return_train_score)

        self.fit_params = fit_params if fit_params is not None else {}

        self.sc = sc
        self.param_grid = param_grid

        self.cv_results_ = None
        _check_param_grid(param_grid)
Example #26
0
 def fit(self, X, y):
     self.best_estimator_ = None
     self.best_mem_score_ = float("-inf")
     self.best_mem_params_ = None
     _check_param_grid(self.params)
     self._fit(X, y, self.params)
     if self.refit:
         self.best_estimator_ = clone(self.estimator)
         self.best_estimator_.set_params(**self.best_mem_params_)
         if self.fit_params is not None:
             self.best_estimator_.fit(X, y, **self.fit_params)
         else:
             self.best_estimator_.fit(X, y)
     #print(self.cv_results_())
     return self
Example #27
0
 def __init__(self, default_estimator, param_grid, cv, me, untrainable_param_grid=None,
              scoring_rank='f1_score', refit=False, iid=True, n_jobs=1, pre_dispatch='2*n_jobs',
              logger=StandardOutputLogger(Logger.INFO)):
     self.default_estimator = default_estimator
     self.param_grid = param_grid
     self.untrainable_param_grid = untrainable_param_grid
     self.cv = cv
     self.me = me
     self.scoring_rank = scoring_rank
     self.n_jobs = n_jobs
     self.pre_dispatch = pre_dispatch
     self.logger = logger
     self.refit = refit
     self.iid = iid
     _check_param_grid(param_grid)
     _check_param_grid(untrainable_param_grid)
 def __init__(self, estimator, param_grid, scoring=None, fit_params=None,
              n_jobs=None, iid='warn', refit=True, cv='warn', verbose=0,
              pre_dispatch='2*n_jobs', error_score='raise-deprecating',
              return_train_score="warn",
              cachedir='./', return_estimator=False,
              client=None):
     super(PersGridSearchCV, self).__init__(
         estimator=estimator, scoring=scoring, fit_params=fit_params,
         n_jobs=n_jobs, iid=iid, refit=refit, cv=cv, verbose=verbose,
         pre_dispatch=pre_dispatch, error_score=error_score,
         return_train_score=return_train_score)
     self.param_grid = param_grid
     self.cachedir = cachedir
     self.return_estimator = return_estimator
     self.client = client
     _check_param_grid(param_grid)
    def fit(self, X, y):
        """Fit the model to the training data."""
        X, y = check_X_y(X, y, force_all_finite=False,
                         multi_output=self.multi_output)
        _check_param_grid(self.param_grid)

        # cv = _check_cv(self.cv, X, y, classifier=is_classifier(self.estimator))
        cv = _check_cv(self.cv, y, classifier=is_classifier(self.estimator))

        self.scorer_ = check_scoring(self.estimator, scoring=self.scoring)

        if comm_rank == 0:
            self._fit_master(X, y, cv)
        else:
            self._fit_slave()

        return self
def _normalize_param_grid(param_grid):
    """Normalize the parameter grid to use with
    parametrized estimators."""

    # Check the parameters grid
    _check_param_grid(param_grid)

    # Copy the parameters grid
    normalized_param_grid = param_grid.copy()

    # Parse the estimator name
    est_name = list(set([param.split('__')[0] for param in param_grid.keys()]))

    # Update with the estimator name
    normalized_param_grid.update({'est_name': est_name})

    return normalized_param_grid
Example #31
0
    def __init__(self, estimator, param_grid, known_triples=None, cv=None, n_jobs=1, refit=True, verbose=0):
        """ Initialise an object of the KGEGridSearch class

        Parameters
        ----------
        estimator : estimator object.
            This is assumed to implement the scikit-learn estimator interface.
        param_grid : dict or list of dictionaries
            Dictionary with parameters names (string) as keys and lists of
            parameter settings to try as values, or a list of such
            dictionaries, in which case the grids spanned by each dictionary
            in the list are explored. This enables searching over any sequence
            of parameter settings.
        known_triples : np.ndarray
            array of known triples
        cv : int, cross-validation generator or an iterable, optional
            Determines the cross-validation splitting strategy.
            Possible inputs for cv are:
              - None, to use the default KGE train/valid gridsearch,
              - integer, to specify the number of folds in a scikit-learn `(Stratified)KFold`,
              - An object to be used as a cross-validation generator.
              - An iterable yielding train, test splits.
        n_jobs : int
            number of parallel jobs
        verbose : int
            level of logging verbosity
        """

        super(KGEGridSearch, self).__init__(estimator=estimator,
                                            fit_params=None,
                                            n_jobs=n_jobs,
                                            iid=True,
                                            refit=refit,
                                            cv=cv,
                                            verbose=verbose,
                                            pre_dispatch='2*n_jobs',
                                            error_score='raise',
                                            return_train_score=False)

        self.cv = cv
        self.param_grid = param_grid
        self.valid_data = None
        self.known_triples = known_triples
        _check_param_grid(param_grid)
    def fit(self, X, y):
        """Fit the model to the training data."""
        X, y = check_X_y(X,
                         y,
                         force_all_finite=False,
                         multi_output=self.multi_output)
        _check_param_grid(self.param_grid)

        # cv = _check_cv(self.cv, X, y, classifier=is_classifier(self.estimator))
        cv = _check_cv(self.cv, y, classifier=is_classifier(self.estimator))

        self.scorer_ = check_scoring(self.estimator, scoring=self.scoring)

        if comm_rank == 0:
            self._fit_master(X, y, cv)
        else:
            self._fit_slave()

        return self
    def fit(self, cvs, groups=None, **fit_params):
        X = np.vstack((cvs[0][0], cvs[0][2], cvs[0][4]))

        if len(cvs[0][1].shape)==1 and len(cvs[0][5].shape)==1:
            y = np.hstack((cvs[0][1], cvs[0][3], cvs[0][5]))
        else:
            y = np.vstack((cvs[0][1], cvs[0][3], cvs[0][5])).ravel()
        self.best_estimator_ = None
        self.best_mem_score_ = float("-inf")
        self.best_mem_params_ = None
        for possible_params in self.possible_params:
            _check_param_grid(possible_params)
            self._fit(X, y, cvs, possible_params)
        if self.refit:
            self.best_estimator_ = clone(self.estimator)
            self.best_estimator_.set_params(**self.best_mem_params_)
            if self.fit_params is not None:
                self.best_estimator_.fit(X, y, **self.fit_params)
            else:
                self.best_estimator_.fit(X, y)
Example #34
0
 def __init__(self,
              estimator,
              param_grid,
              scoring=None,
              fit_params=None,
              n_jobs=1,
              iid=True,
              refit=True,
              cv=None,
              verbose=0,
              pre_dispatch='2*n_jobs',
              error_score='raise',
              return_train_score=True,
              client_kwargs=settings.DASK_SCHEDULER_PARAMS,
              uuid='',
              dataset=None,
              webserver_url='http://127.0.0.1:8000'):
     super(GridSearchCV,
           self).__init__(estimator=estimator,
                          scoring=scoring,
                          fit_params=fit_params,
                          n_jobs=n_jobs,
                          iid=iid,
                          refit=refit,
                          cv=cv,
                          verbose=verbose,
                          pre_dispatch=pre_dispatch,
                          error_score=error_score,
                          return_train_score=return_train_score)
     from AnyTimeGridSearchCV.grids.models import GridSearch, DataSet
     self.param_grid = param_grid
     _check_param_grid(param_grid)
     self.dask_client = Client(silence_logs=100, **client_kwargs)
     self.dask_client.upload_file(settings.SOURCE_PATH)
     self.dataset, _ = DataSet.objects.get_or_create(
         pk=dataset) if dataset is not None else (None, None)
     self._uuid = uuid if uuid else GridSearch.objects.create(
         classifier=type(estimator).__name__, dataset=self.dataset).uuid
     self.webserver_url = webserver_url