code: def _fit_and_score(
      estimator,
      X,
      y,
      scorer,
      train,
      test,
      parameters,
      fit_params,
      return_train_score=False,
      return_parameters=False,
      return_n_test_samples=False,
      return_times=False,
      error_score="raise",
      *,
      verbose=None,
      position=0,
  ):
      """Fit estimator and compute scores for a given dataset split."""
      #  This code is adapted from sklearn
      from sklearn.utils.metaestimators import _safe_split
      from sklearn.utils.validation import _num_samples
  
      # Adjust length of sample weights
      fit_params = fit_params if fit_params is not None else {}
      fit_params = _check_fit_params(X, fit_params, train)
  
      if parameters is not None:
          estimator.set_params(**parameters)
  
      start_time = dt.datetime.now()
  
      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_duration = dt.datetime.now() - start_time
          score_duration = dt.timedelta(0)
          if error_score == "raise":
              raise
          elif isinstance(error_score, numbers.Number):
              test_score = error_score
              if return_train_score:
                  train_score = error_score
              warn(
                  "Classifier fit failed. The score on this train-test partition for "
                  f"these parameters will be set to {error_score}. Details: \n{e!r}"
              )
          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_duration = dt.datetime.now() - start_time
          test_score = _score(estimator, X_test, y_test, scorer)
          score_duration = dt.datetime.now() - start_time - fit_duration
          if return_train_score:
              train_score = _score(estimator, X_train, y_train, scorer)
  
      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_duration.total_seconds(),
                  score_duration.total_seconds(),
              ]
          )
      if return_parameters:
          ret.append(parameters)
      return ret
  
imports: import datetime
  import numbers
  import numpy
  from ..fixes import BaseEstimator, _check_fit_params, _get_check_scoring
  from ..parallel import parallel_func
  from ..utils import verbose, warn
label_desc: Use image node_id 6 for calling a global function with example usage: _fit_and_score(estimator, X, y, scorer, train, test, parameters, fit_params, return_train_score, return_parameters, return_n_test_samples, return_times, error_score) and returns: ret