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(
              scorers=scorer, raise_exc=(error_score == "raise")
          )
  
      try:
          if y_test is None:
              scores = scorer(estimator, X_test)
          else:
              scores = scorer(estimator, X_test, y_test)
      except Exception:
          if isinstance(scorer, _MultimetricScorer):
              # If `_MultimetricScorer` raises exception, the `error_score`
              # parameter is equal to "raise".
              raise
          else:
              if error_score == "raise":
                  raise
              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,
                  )
  
      # Check non-raised error messages in `_MultimetricScorer`
      if isinstance(scorer, _MultimetricScorer):
          exception_messages = [
              (name, str_e)
              for name, str_e in scores.items()
              if isinstance(str_e, str)
          ]
          if exception_messages:
              # error_score != "raise"
              for name, str_e in exception_messages:
                  scores[name] = 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"{str_e}"
                      ),
                      UserWarning,
                  )
  
      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 numbers
  import time
  import warnings
  from collections import Counter
  from contextlib import suppress
  from functools import partial
  from numbers import Real
  from traceback import format_exc
  import numpy
  import scipy.sparse
  from joblib import logger
  from ..base import clone, is_classifier
  from ..exceptions import FitFailedWarning
  from ..metrics import check_scoring, get_scorer_names
  from ..metrics._scorer import _check_multimetric_scoring, _MultimetricScorer
  from ..preprocessing import LabelEncoder
  from ..utils import _safe_indexing, check_random_state, indexable
  from ..utils._param_validation import HasMethods, Integral, Interval, StrOptions, validate_params
  from ..utils.metaestimators import _safe_split
  from ..utils.parallel import Parallel, delayed
  from ..utils.validation import _check_fit_params, _num_samples
  from ._split import check_cv
label_desc: Use image node_id 7 for calling a global function with example usage: _score(estimator, X_test, y_test, scorer, error_score) and returns: scores