code: def cross_validate(
      estimator,
      y,
      X=None,
      scoring=None,
      cv=None,
      verbose=0,
      error_score=np.nan,
  ):
      """Evaluate metric(s) by cross-validation and also record fit/score times.
  
      Parameters
      ----------
      estimator : estimator
          An estimator object that implements the ``fit`` method
  
      y : array-like or iterable, shape=(n_samples,)
              The time-series array.
  
      X : array-like, shape=[n_obs, n_vars], optional (default=None)
          An optional 2-d array of exogenous variables.
  
      scoring : str or callable, optional (default=None)
          The scoring metric to use. If a callable, must adhere to the signature
          ``metric(true, predicted)``. Valid string scoring metrics include:
  
          - 'smape'
          - 'mean_absolute_error'
          - 'mean_squared_error'
  
      cv : BaseTSCrossValidator or None, optional (default=None)
          An instance of cross-validation. If None, will use a RollingForecastCV
  
      verbose : integer, optional
          The verbosity level.
  
      error_score : 'raise' 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, ModelFitWarning is raised. This parameter
          does not affect the refit step, which will always raise the error.
      """
      y, X = indexable(y, X)
      y = check_endog(y, copy=False, preserve_series=True)
  
      cv = check_cv(cv)
      scoring = _check_scoring(scoring)
  
      # validate the error score
      if not (
          error_score == "raise"
          or isinstance(error_score, numbers.Number)
      ):
          raise ValueError(
              'error_score should be the string "raise" or a '
              "numeric value"
          )
  
      # TODO: in the future we might consider joblib for parallelizing, but it
      #   . could cause cross threads in parallelism..
  
      results = [
          _fit_and_score(
              fold,
              base.clone(estimator),
              y,
              X,
              scorer=scoring,
              train=train,
              test=test,
              verbose=verbose,
              error_score=error_score,
          )
          for fold, (train, test) in enumerate(cv.split(y, X))
      ]
      scores, fit_times, score_times = list(zip(*results))
  
      ret = {
          "test_score": np.array(scores),
          "fit_time": np.array(fit_times),
          "score_time": np.array(score_times),
      }
      return ret
  
imports: import numpy
  import numbers
  import warnings
  import time
  from traceback import format_exception_only
  from sklearn import base
  from sklearn.metrics import mean_absolute_error, mean_squared_error
  from sklearn.utils import indexable
  from ._split import check_cv
  from ..None import metrics
  from ..utils import check_endog
  from ..warnings import ModelFitWarning
  from ..compat.sklearn import safe_indexing
label_desc: Use image node_id 7 for calling a global function with example usage: cross_validate(estimator, y, X, scoring, cv, verbose, error_score) and returns: ret