(self)
return cvbooster
Return the best cvbooster.

        If the best booster cannot be found, :class:`ValueError` will be raised.
        To prevent the errors, please save boosters by specifying
        both of the ``model_dir`` and the ``return_cvbooster`` arguments of
        :meth:`~optuna.integration.lightgbm.LightGBMTunerCV.__init__`,
        when you resume tuning or you run tuning in parallel.
Return the best cvbooster.
Return the best cvbooster .
def get_best_booster(self) -> "lgb.CVBooster":
        """Return the best cvbooster.

        If the best booster cannot be found, :class:`ValueError` will be raised.
        To prevent the errors, please save boosters by specifying
        both of the ``model_dir`` and the ``return_cvbooster`` arguments of
        :meth:`~optuna.integration.lightgbm.LightGBMTunerCV.__init__`,
        when you resume tuning or you run tuning in parallel.
        """
        if self.lgbm_kwargs.get("return_cvbooster") is not True:
            raise ValueError(
                "LightGBMTunerCV requires `return_cvbooster=True` for method `get_best_booster()`."
            )
        if self._best_booster_with_trial_number is not None:
            if self._best_booster_with_trial_number[1] == self.study.best_trial.number:
                return self._best_booster_with_trial_number[0]
        if len(self.study.trials) == 0:
            raise ValueError("The best booster is not available because no trials completed.")

        # The best booster exists, but this instance does not have it.
        # This may be due to resuming or parallelization.
        if self._model_dir is None:
            raise ValueError(
                "The best booster cannot be found. It may be found in the other processes due to "
                "resuming or distributed computing. Please set the `model_dir` argument of "
                "`LightGBMTunerCV.__init__` and make sure that boosters are shared with all "
                "processes."
            )

        best_trial = self.study.best_trial
        path = os.path.join(self._model_dir, "{}.pkl".format(best_trial.number))
        if not os.path.exists(path):
            raise ValueError(
                "The best booster cannot be found in {}. If you execute `LightGBMTunerCV` in "
                "distributed environment, please use network file system (e.g., NFS) to share "
                "models with multiple workers.".format(self._model_dir)
            )

        with open(path, "rb") as fin:
            boosters, best_iteration = pickle.load(fin)
            # At version `lightgbm==3.0.0`, :class:`lightgbm.CVBooster` does not
            # have `__getstate__` which is required for pickle serialization.
            cvbooster = lgb.CVBooster()
            cvbooster.boosters = boosters
            cvbooster.best_iteration = best_iteration

        return cvbooster
def get_best_booster ( self ) -> "lgb.CVBooster" : if self . lgbm_kwargs . get ( "return_cvbooster" ) is not True : raise ValueError ( "LightGBMTunerCV requires `return_cvbooster=True` for method `get_best_booster()`." ) if self . _best_booster_with_trial_number is not None : if self . _best_booster_with_trial_number [ 1 ] == self . study . best_trial . number : return self . _best_booster_with_trial_number [ 0 ] if len ( self . study . trials ) == 0 : raise ValueError ( "The best booster is not available because no trials completed." ) # The best booster exists, but this instance does not have it. # This may be due to resuming or parallelization. if self . _model_dir is None : raise ValueError ( "The best booster cannot be found. It may be found in the other processes due to " "resuming or distributed computing. Please set the `model_dir` argument of " "`LightGBMTunerCV.__init__` and make sure that boosters are shared with all " "processes." ) best_trial = self . study . best_trial path = os . path . join ( self . _model_dir , "{}.pkl" . format ( best_trial . number ) ) if not os . path . exists ( path ) : raise ValueError ( "The best booster cannot be found in {}. If you execute `LightGBMTunerCV` in " "distributed environment, please use network file system (e.g., NFS) to share " "models with multiple workers." . format ( self . _model_dir ) ) with open ( path , "rb" ) as fin : boosters , best_iteration = pickle . load ( fin ) # At version `lightgbm==3.0.0`, :class:`lightgbm.CVBooster` does not # have `__getstate__` which is required for pickle serialization. cvbooster = lgb . CVBooster ( ) cvbooster . boosters = boosters cvbooster . best_iteration = best_iteration return cvbooster