code: def cross_val_predict(
      estimator,
      y,
      X=None,
      cv=None,
      verbose=0,
      averaging="mean",
      return_raw_predictions=False,
  ):
      """Generate cross-validated estimates for each input data point
  
      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.
  
      cv : BaseTSCrossValidator or None, optional (default=None)
          An instance of cross-validation. If None, will use a RollingForecastCV.
          Note that for cross-validation predictions, the CV step cannot exceed
          the CV horizon, or there will be a gap between fold predictions.
  
      verbose : integer, optional
          The verbosity level.
  
      averaging : str or callable, one of ["median", "mean"] (default="mean")
          Unlike normal CV, time series CV might have different folds (windows)
          forecasting the same time step. After all forecast windows are made,
          we build a matrix of y x n_folds, populating each fold's forecasts like
          so::
  
              nan nan nan  # training samples
              nan nan nan
              nan nan nan
              nan nan nan
                1 nan nan  # test samples
                4   3 nan
                3 2.5 3.5
              nan   6   5
              nan nan   4
  
          We then average each time step's forecasts to end up with our final
          prediction results.
  
      return_raw_predictions : bool (default=False)
          If True, raw predictions are returned instead of averaged ones.
          This results in a y x h matrix. For example, if h=3, and step=1 then:
  
              nan nan nan # training samples
              nan nan nan
              nan nan nan
              nan nan nan
              1   4   2   # test samples
              2   5   7
              8   9   1
              nan nan nan
              nan nan nan
  
          First column contains all one-step-ahead-predictions, second column all
          two-step-ahead-predictions etc. Further metrics can then be calculated
          as desired.
      
  
      Examples
      --------
      >>> import pmdarima as pm
      >>> from pmdarima.model_selection import cross_val_predict,\
      ...     RollingForecastCV
      >>> y = pm.datasets.load_wineind()
      >>> cv = RollingForecastCV(h=14, step=12)
      >>> preds = cross_val_predict(
      ...     pm.ARIMA((1, 1, 2), seasonal_order=(0, 1, 1, 12)), y, cv=cv)
      >>> preds[:5]
      array([30710.45743168, 34902.94929722, 17994.16587163, 22127.71167249,
             25473.60876435])
      """
      y, X = indexable(y, X)
      y = check_endog(y, copy=False, preserve_series=True)
      cv = check_cv(cv)
      avgfunc = _check_averaging(averaging)
  
      # need to be careful here:
      # >>> cv = RollingForecastCV(step=6, h=4)
      # >>> cv_generator = cv.split(wineind)
      # >>> next(cv_generator)
      # (array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
      #         15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
      #         30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
      #         45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]),
      #  array([58, 59, 60, 61]))
      # >>> next(cv_generator)
      # (array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
      #         15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
      #         30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
      #         45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
      #         60, 61, 62, 63]),
      #  array([64, 65, 66, 67]))  <~~ 64 vs. 61
      if cv.step > cv.horizon:
          raise ValueError(
              "CV step cannot be > CV horizon, or there will be a "
              "gap in predictions between folds"
          )
  
      # clone estimator to make sure all folds are independent
      prediction_blocks = [
          _fit_and_predict(
              fold,
              base.clone(estimator),
              y,
              X,
              train=train,
              test=test,
              verbose=verbose,
          )  # TODO: fit params?
          for fold, (train, test) in enumerate(cv.split(y, X))
      ]
  
      # Unlike normal CV, time series CV might have different folds (windows)
      # forecasting the same time step. In this stage, we build a matrix of
      # y x n_folds, populating each fold's forecasts like so:
  
      pred_matrix = (
          np.ones((y.shape[0], len(prediction_blocks))) * np.nan
      )
      for i, (pred_block, test_indices) in enumerate(prediction_blocks):
          pred_matrix[test_indices, i] = pred_block
  
      if return_raw_predictions:
          predictions = np.ones((y.shape[0], cv.horizon)) * np.nan
          for pred_block, test_indices in prediction_blocks:
              predictions[test_indices[0]] = pred_block
          return predictions
  
      # from there, we need to apply nanmean (or some other metric) along rows
      # to agree on a forecast for a sample.
      test_mask = ~(np.isnan(pred_matrix).all(axis=1))
      predictions = pred_matrix[test_mask]
      return avgfunc(predictions, axis=1)
  
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 8 for calling a global function with example usage: cross_val_predict(estimator, y, X, cv, verbose, averaging, return_raw_predictions) and returns: avgfunc, predictions