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.
  
      Parameters
      ----------
      estimator : estimator object implementing 'fit'
          The object to use to fit the data.
  
      X : array-like of shape at least 2D
          The data to fit.
  
      y : array-like, optional, default: None
          The target variable to try to predict in the case of
          supervised learning.
  
      scorer : callable
          A scorer callable object / function with signature
          ``scorer(estimator, X, y)``.
  
      train : array-like, shape (n_train_samples,)
          Indices of training samples.
  
      test : array-like, shape (n_test_samples,)
          Indices of test samples.
  
      verbose : integer
          The verbosity level.
  
      error_score : 'raise' (default) or numeric
          Value to assign to the score if an error occurs in estimator fitting.
          If set to 'raise', the error is raised. If a numeric value is given,
          FitFailedWarning is raised. This parameter does not affect the refit
          step, which will always raise the error.
  
      parameters : dict or None
          Parameters to be set on the estimator.
  
      fit_params : dict or None
          Parameters that will be passed to ``estimator.fit``.
  
      return_train_score : boolean, optional, default: False
          Compute and return score on training set.
  
      return_parameters : boolean, optional, default: False
          Return parameters that has been used for the estimator.
  
      Returns
      -------
      train_score : float, optional
          Score on training set, returned only if `return_train_score` is `True`.
  
      test_score : float
          Score on test set.
  
      n_test_samples : int
          Number of test samples.
  
      fit_time : float
          Time spent for fitting in seconds.
  
      score_time : float
          Time spent for scoring in seconds.
  
      parameters : dict or None, optional
          The parameters that have been evaluated.
      """
      if verbose > 1:
          if parameters is None:
              msg = ""
          else:
              msg = "%s" % (
                  ", ".join(
                      "%s=%s" % (k, v) for k, v in 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 fit_params.items()
          ]
      )
  
      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)
  
      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):
              test_score = error_score
              if return_train_score:
                  train_score = 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
          test_score = _score(estimator, X_test, y_test, scorer)
          score_time = time.time() - start_time - fit_time
          if return_train_score:
              train_score = _score(estimator, X_train, y_train, scorer)
  
      if verbose > 2:
          msg += ", score=%f" % test_score
      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_score, test_score]
          if return_train_score
          else [test_score]
      )
  
      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: from __future__ import print_function
  from __future__ import division
  import warnings
  import numbers
  import time
  import numpy
  import scipy.sparse
  from ..base import is_classifier, clone
  from ..utils import indexable, check_random_state, safe_indexing
  from ..utils.fixes import astype
  from ..utils.validation import _is_arraylike, _num_samples
  from ..utils.metaestimators import _safe_split
  from ..externals.joblib import Parallel, delayed, logger
  from ..metrics.scorer import check_scoring
  from ..exceptions import FitFailedWarning
  from ._split import check_cv
label_desc: Use image node_id 2 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