(self, study_id: int)
return best_trial
Return the trial with the best value in a study.

        This method is valid only during single-objective optimization.

        Args:
            study_id:
                ID of the study.

        Returns:
            The trial with the best objective value among all finished trials in the study.

        Raises:
            :exc:`KeyError`:
                If no study with the matching ``study_id`` exists.
            :exc:`RuntimeError`:
                If the study has more than one direction.
            :exc:`ValueError`:
                If no trials have been completed.
Return the trial with the best value in a study.
Return the trial with the best value in a study .
def get_best_trial(self, study_id: int) -> FrozenTrial:
        """Return the trial with the best value in a study.

        This method is valid only during single-objective optimization.

        Args:
            study_id:
                ID of the study.

        Returns:
            The trial with the best objective value among all finished trials in the study.

        Raises:
            :exc:`KeyError`:
                If no study with the matching ``study_id`` exists.
            :exc:`RuntimeError`:
                If the study has more than one direction.
            :exc:`ValueError`:
                If no trials have been completed.
        """
        all_trials = self.get_all_trials(study_id, deepcopy=False)
        all_trials = [t for t in all_trials if t.state is TrialState.COMPLETE]

        if len(all_trials) == 0:
            raise ValueError("No trials are completed yet.")

        directions = self.get_study_directions(study_id)
        if len(directions) > 1:
            raise RuntimeError(
                "Best trial can be obtained only for single-objective optimization."
            )
        direction = directions[0]

        if direction == StudyDirection.MAXIMIZE:
            best_trial = max(all_trials, key=lambda t: cast(float, t.value))
        else:
            best_trial = min(all_trials, key=lambda t: cast(float, t.value))

        return best_trial
def get_best_trial ( self , study_id : int ) -> FrozenTrial : all_trials = self . get_all_trials ( study_id , deepcopy = False ) all_trials = [ t for t in all_trials if t . state is TrialState . COMPLETE ] if len ( all_trials ) == 0 : raise ValueError ( "No trials are completed yet." ) directions = self . get_study_directions ( study_id ) if len ( directions ) > 1 : raise RuntimeError ( "Best trial can be obtained only for single-objective optimization." ) direction = directions [ 0 ] if direction == StudyDirection . MAXIMIZE : best_trial = max ( all_trials , key = lambda t : cast ( float , t . value ) ) else : best_trial = min ( all_trials , key = lambda t : cast ( float , t . value ) ) return best_trial