code: def _score(estimator, X_test, y_test, scorer, error_score="raise"):
      """Compute the score(s) of an estimator on a given test set.
  
      Will return a dict of floats if `scorer` is a dict, otherwise a single
      float is returned.
      """
      if isinstance(scorer, dict):
          # will cache method calls if needed. scorer() returns a dict
          scorer = _MultimetricScorer(**scorer)
  
      try:
          if y_test is None:
              scores = scorer(estimator, X_test)
          else:
              scores = scorer(estimator, X_test, y_test)
      except Exception:
          if error_score == "raise":
              raise
          else:
              if isinstance(scorer, _MultimetricScorer):
                  scores = {
                      name: error_score for name in scorer._scorers
                  }
              else:
                  scores = error_score
              warnings.warn(
                  "Scoring failed. The score on this train-test partition for "
                  f"these parameters will be set to {error_score}. Details: \n"
                  f"{format_exc()}",
                  UserWarning,
                  stacklevel=1,
              )
  
      error_msg = "scoring must return a number, got %s (%s) instead. (scorer=%s)"
      if isinstance(scores, dict):
          for name, score in scores.items():
              if hasattr(score, "item"):
                  with suppress(ValueError):
                      # e.g. unwrap memmapped scalars
                      score = score.item()
              if not isinstance(score, numbers.Number):
                  raise ValueError(
                      error_msg % (score, type(score), name)
                  )
              scores[name] = score
      else:  # scalar
          if hasattr(scores, "item"):
              with suppress(ValueError):
                  # e.g. unwrap memmapped scalars
                  scores = scores.item()
          if not isinstance(scores, numbers.Number):
              raise ValueError(
                  error_msg % (scores, type(scores), scorer)
              )
      return scores
  
imports: import functools
  import logging
  import numbers
  import time
  import warnings
  from collections import Counter
  from contextlib import suppress
  from itertools import compress
  from traceback import format_exc
  import numpy
  import scipy.sparse
  from catboost import CatBoostClassifier, CatBoostRegressor
  from joblib import Parallel, logger
  from scipy.sparse import issparse
  from sklearn import config_context, get_config
  from sklearn.base import clone, is_classifier
  from sklearn.exceptions import FitFailedWarning, NotFittedError
  from sklearn.metrics import check_scoring
  from sklearn.metrics._scorer import _MultimetricScorer
  from sklearn.model_selection import check_cv
  from sklearn.utils.fixes import np_version, parse_version
  from sklearn.utils.validation import indexable
label_desc: Use image node_id 8 for calling a global function with example usage: _score(estimator, X_test, y_test, scorer, error_score) and returns: scores