class_docstr: Abstract base class for hyper parameter search with cross-validation.
class_docstr_tok: ["Abstract","base","class","for","hyper","parameter","search","with","cross-validation","."]
code: def _format_results(
      self, candidate_params, n_splits, out, more_results=None
  ):
      n_candidates = len(candidate_params)
      out = _aggregate_score_dicts(out)
  
      results = dict(more_results or {})
      for key, val in results.items():
          # each value is a list (as per evaluate_candidate's convention)
          # we convert it to an array for consistency with the other keys
          results[key] = np.asarray(val)
  
      def _store(
          key_name, array, weights=None, splits=False, rank=False
      ):
          """A small helper to store the scores/times to the cv_results_"""
          # When iterated first by splits, then by parameters
          # We want `array` to have `n_candidates` rows and `n_splits` cols.
          array = np.array(array, dtype=np.float64).reshape(
              n_candidates, n_splits
          )
          if splits:
              for split_idx in range(n_splits):
                  # Uses closure to alter the results
                  results["split%d_%s" % (split_idx, key_name)] = array[
                      :, split_idx
                  ]
  
          array_means = np.average(array, axis=1, weights=weights)
          results["mean_%s" % key_name] = array_means
  
          if key_name.startswith(("train_", "test_")) and np.any(
              ~np.isfinite(array_means)
          ):
              warnings.warn(
                  (
                      f"One or more of the {key_name.split('_')[0]} scores "
                      f"are non-finite: {array_means}"
                  ),
                  category=UserWarning,
              )
  
          # Weighted std is not directly available in numpy
          array_stds = np.sqrt(
              np.average(
                  (array - array_means[:, np.newaxis]) ** 2,
                  axis=1,
                  weights=weights,
              )
          )
          results["std_%s" % key_name] = array_stds
  
          if rank:
              # When the fit/scoring fails `array_means` contains NaNs, we
              # will exclude them from the ranking process and consider them
              # as tied with the worst performers.
              if np.isnan(array_means).all():
                  # All fit/scoring routines failed.
                  rank_result = np.ones_like(
                      array_means, dtype=np.int32
                  )
              else:
                  min_array_means = np.nanmin(array_means) - 1
                  array_means = np.nan_to_num(
                      array_means, nan=min_array_means
                  )
                  rank_result = rankdata(
                      -array_means, method="min"
                  ).astype(np.int32, copy=False)
              results["rank_%s" % key_name] = rank_result
  
      _store("fit_time", out["fit_time"])
      _store("score_time", out["score_time"])
      # Use one MaskedArray and mask all the places where the param is not
      # applicable for that candidate. Use defaultdict as each candidate may
      # not contain all the params
      param_results = defaultdict(
          partial(
              MaskedArray,
              np.empty(
                  n_candidates,
              ),
              mask=True,
              dtype=object,
          )
      )
      for cand_idx, params in enumerate(candidate_params):
          for name, value in params.items():
              # An all masked empty array gets created for the key
              # `"param_%s" % name` at the first occurrence of `name`.
              # Setting the value at an index also unmasks that index
              param_results["param_%s" % name][cand_idx] = value
  
      results.update(param_results)
      # Store a list of param dicts at the key 'params'
      results["params"] = candidate_params
  
      test_scores_dict = _normalize_score_results(out["test_scores"])
      if self.return_train_score:
          train_scores_dict = _normalize_score_results(
              out["train_scores"]
          )
  
      for scorer_name in test_scores_dict:
          # Computed the (weighted) mean and std for test scores alone
          _store(
              "test_%s" % scorer_name,
              test_scores_dict[scorer_name],
              splits=True,
              rank=True,
              weights=None,
          )
          if self.return_train_score:
              _store(
                  "train_%s" % scorer_name,
                  train_scores_dict[scorer_name],
                  splits=True,
              )
  
      return results
  
imports: import numbers
  import operator
  import time
  import warnings
  from abc import ABCMeta, abstractmethod
  from collections import defaultdict
  from collections.abc import Iterable, Mapping, Sequence
  from functools import partial, reduce
  from itertools import product
  import numpy
  from numpy.ma import MaskedArray
  from scipy.stats import rankdata
  from ..base import BaseEstimator, MetaEstimatorMixin, _fit_context, clone, is_classifier
  from ..exceptions import NotFittedError
  from ..metrics import check_scoring
  from ..metrics._scorer import _check_multimetric_scoring, get_scorer_names
  from ..utils import check_random_state
  from ..utils._param_validation import HasMethods, Interval, StrOptions
  from ..utils._tags import _safe_tags
  from ..utils.metaestimators import available_if
  from ..utils.parallel import Parallel, delayed
  from ..utils.random import sample_without_replacement
  from ..utils.validation import _check_fit_params, check_is_fitted, indexable
  from ._split import check_cv
  from ._validation import _aggregate_score_dicts, _fit_and_score, _insert_error_scores, _normalize_score_results, _warn_or_raise_about_fit_failures
label_desc: Use image node_id 18 for calling the BaseSearchCV obj's underlying member method code with example usage: obj._format_results(candidate_params, n_splits, out, more_results) and returns: results