ray.tune.ExperimentAnalysis.get_best_trial#
- ExperimentAnalysis.get_best_trial(metric: str | None = None, mode: str | None = None, scope: str = 'last', filter_nan_and_inf: bool = True) Trial | None[source]#
- Retrieve the best trial object. - Compares all trials’ scores on - metric. If- metricis not specified,- self.default_metricwill be used. If- modeis not specified,- self.default_modewill be used. These values are usually initialized by passing the- metricand- modeparameters to- tune.run().- Parameters:
- metric – Key for trial info to order on. Defaults to - self.default_metric.
- mode – One of [min, max]. Defaults to - self.default_mode.
- scope – One of [all, last, avg, last-5-avg, last-10-avg]. If - scope=last, only look at each trial’s final step for- metric, and compare across trials based on- mode=[min,max]. If- scope=avg, consider the simple average over all steps for- metricand compare across trials based on- mode=[min,max]. If- scope=last-5-avgor- scope=last-10-avg, consider the simple average over the last 5 or 10 steps for- metricand compare across trials based on- mode=[min,max]. If- scope=all, find each trial’s min/max score for- metricbased on- mode, and compare trials based on- mode=[min,max].
- filter_nan_and_inf – If True (default), NaN or infinite values are disregarded and these trials are never selected as the best trial. 
 
- Returns:
- The best trial for the provided metric. If no trials contain the provided
- metric, or if the value for the metric is NaN for all trials, then returns None.