code: def _fit_and_score(
      estimator,
      X,
      y,
      scorer,
      train,
      test,
      verbose,
      parameters,
      fit_params,
      return_train_score=False,
      return_parameters=False,
      return_n_test_samples=False,
      return_times=False,
      error_score="raise",
  ):
      """Fit estimator and compute scores for a given dataset split"""
      estimator_ = _clone(_get_value(estimator))
      if verbose > 1:
          if parameters is None:
              msg = ""
          else:
              msg = "%s" % (
                  ", ".join(
                      "%s=%s" % (k, v)
                      for k, v in list(parameters.items())
                  )
              )
          print(("[CV] %s %s" % (msg, (64 - len(msg)) * ".")))
  
      # Adjust length of sample weights
      fit_params = fit_params if fit_params is not None else {}
      fit_params = dict(
          [
              (k, _index_param_value(X, v, train))
              for k, v in list(fit_params.items())
          ]
      )
  
      test_scores = {}
      train_scores = {}
      if parameters is not None:
          estimator_.set_params(**parameters)
  
      start_time = time.time()
  
      X_train, y_train = _safe_split(estimator_, X, y, train)
      X_test, y_test = _safe_split(estimator_, X, y, test, train)
  
      is_multimetric = not callable(scorer)
      n_scorers = len(list(scorer.keys())) if is_multimetric else 1
  
      try:
          if y_train is None:
              estimator_.fit(X_train, **fit_params)
          else:
              estimator_.fit(X_train, y_train, **fit_params)
  
      except Exception as e:
          # Note fit time as time until error
          fit_time = time.time() - start_time
          score_time = 0.0
          if error_score == "raise":
              raise
          elif isinstance(error_score, numbers.Number):
              score_dict = dict(
                  list(
                      zip(
                          list(scorer.keys()), [error_score] * n_scorers
                      )
                  )
              )
              if is_multimetric:
                  test_scores = score_dict
                  if return_train_score:
                      train_scores = score_dict
              else:
                  test_scores = error_score
                  if return_train_score:
                      train_scores = error_score
              warnings.warn(
                  "Classifier fit failed. The score on this train-test"
                  " partition for these parameters will be set to %f. "
                  "Details: \n%r" % (error_score, e),
                  FitFailedWarning,
              )
          else:
              raise ValueError(
                  "error_score must be the string 'raise' or a"
                  " numeric value. (Hint: if using 'raise', please"
                  " make sure that it has been spelled correctly.)"
              )
  
      else:
          fit_time = time.time() - start_time
          # _score will return dict if is_multimetric is True
          test_scores = _score(
              estimator_, X_test, y_test, scorer, is_multimetric
          )
          score_time = time.time() - start_time - fit_time
          if return_train_score:
              train_scores = _score(
                  estimator_, X_train, y_train, scorer, is_multimetric
              )
  
      if verbose > 2:
          if is_multimetric:
              for scorer_name, score in list(test_scores.items()):
                  msg += ", %s=%s" % (scorer_name, score)
          else:
              msg += ", score=%s" % test_scores
      if verbose > 1:
          total_time = score_time + fit_time
          end_msg = "%s, total=%s" % (
              msg,
              logger.short_format_time(total_time),
          )
          print(("[CV] %s %s" % ((64 - len(end_msg)) * ".", end_msg)))
  
      ret = (
          [train_scores, test_scores]
          if return_train_score
          else [test_scores]
      )
  
      if return_n_test_samples:
          ret.append(_num_samples(X_test))
      if return_times:
          ret.extend([fit_time, score_time])
      if return_parameters:
          ret.append(parameters)
      return ret
  
imports: import time
  import numbers
  import random
  import numpy
  import pandas
  from copy import copy
  from abc import ABCMeta
  from joblib import Parallel, delayed
  from sklearn.model_selection import ParameterGrid, GridSearchCV, RandomizedSearchCV, ParameterSampler, check_cv
  from sklearn.metrics import check_scoring
  from sklearn.base import BaseEstimator, is_classifier
  from sklearn.utils.metaestimators import if_delegate_has_method
  from sklearn.utils.validation import indexable
  from functools import partial
  from numpy.ma import MaskedArray
  from scipy.stats import rankdata
  from scipy.sparse import issparse
  from itertools import product
  from collections import defaultdict
  from .validation import _check_estimator, _check_base_estimator, _validate_params, _validate_models, _validate_names, _validate_estimators, _check_n_iter, _is_arraylike, _num_samples, _safe_indexing, _check_is_fitted
  from .utils import _multimetric_score, _num_samples, _aggregate_score_dicts, _score, _check_multimetric_scoring, _safe_split, _dict_slice_remove
  from .base import _clone, _get_value, _parse_partitions
label_desc: Use image node_id 7 for calling a global function with example usage: _fit_and_score(estimator, X, y, scorer, train, test, verbose, parameters, fit_params, return_train_score, return_parameters, return_n_test_samples, return_times, error_score) and returns: ret