code: def get_best_index(results, metric="score", greater_is_better=False):
      """Suitable for use as the `refit` parameter to
      `~sklearn.model_selection.RandomizedSearchCV`, after wrapping
      with `functools.partial`.
  
      Callable that takes ``cv_results_`` from grid search
      and returns the best index.
  
      Parameters
      ----------
      results : `dict` [`str`, `numpy.array`]
          Results from CV grid search.
          See `~sklearn.model_selection.RandomizedSearchCV`
          ``cv_results_`` attribute for the format.
      metric : `str`, default "score"
          Which metric to use to select the best parameters.
          In single metric evaluation, the metric name should be "score".
          For multi-metric evaluation, the ``scoring`` parameter to
          `~sklearn.model_selection.RandomizedSearchCV` is a dictionary,
          and ``metric`` must be a key of ``scoring``.
      greater_is_better : `bool`, default False
          If True, selects the parameters with highest test values
          for ``metric``. Otherwise, selects those with the lowest
          test values for ``metric``.
  
      Returns
      -------
      best_index : `int`
          Best index to use for refitting the model.
  
      Examples
      --------
      >>> from functools import partial
      >>> from sklearn.model_selection import RandomizedSearchCV
      >>> refit = partial(get_best_index, metric="score", greater_is_better=False)
      >>> # RandomizedSearchCV(..., refit=refit)
      """
      if greater_is_better:
          # Note: in case of ties, the index corresponds to the first
          #   optimal value. But the order during CV may not match the order
          #   in fitted grid search ``.cv_results_`` attribute.
          # Note: "rank_test_{metric}" is ranked assuming greater_is_better=True,
          #   so these ranks are the opposite of the true ranks if greater_is_better=False.
          best_index = results[f"mean_test_{metric}"].argmax()
      else:
          best_index = results[f"mean_test_{metric}"].argmin()
      return best_index
  
imports: import math
  from functools import partial
  import pandas
  from sklearn.base import clone
  from sklearn.model_selection import ParameterGrid
  from sklearn.model_selection import RandomizedSearchCV
  from sklearn.pipeline import Pipeline
  from greykite.common import constants
  from greykite.common.constants import FRACTION_OUTSIDE_TOLERANCE
  from greykite.common.constants import TIME_COL
  from greykite.common.constants import VALUE_COL
  from greykite.common.evaluation import EvaluationMetricEnum
  from greykite.common.evaluation import add_finite_filter_to_scorer
  from greykite.common.evaluation import add_preaggregation_to_scorer
  from greykite.common.evaluation import fraction_outside_tolerance
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.python_utils import get_integer
  from greykite.common.python_utils import unique_elements_in_list
  from greykite.common.time_properties_forecast import get_default_horizon_from_period
  from greykite.framework.constants import CUSTOM_SCORE_FUNC_NAME
  from greykite.framework.constants import CV_REPORT_METRICS_ALL
  from greykite.framework.constants import FRACTION_OUTSIDE_TOLERANCE_NAME
  from greykite.framework.output.univariate_forecast import UnivariateForecast
  from greykite.sklearn.estimator.simple_silverkite_estimator import SimpleSilverkiteEstimator
  from greykite.sklearn.sklearn_scorer import make_scorer_df
  from greykite.sklearn.transform.column_selector import ColumnSelector
  from greykite.sklearn.transform.difference_based_outlier_transformer import DifferenceBasedOutlierTransformer
  from greykite.sklearn.transform.drop_degenerate_transformer import DropDegenerateTransformer
  from greykite.sklearn.transform.dtype_column_selector import DtypeColumnSelector
  from greykite.sklearn.transform.normalize_transformer import NormalizeTransformer
  from greykite.sklearn.transform.null_transformer import NullTransformer
  from greykite.sklearn.transform.pandas_feature_union import PandasFeatureUnion
label_desc: Use image node_id 1 for calling a global function with example usage: get_best_index(results, metric, greater_is_better) and returns: best_index