class_docstr: Base forecaster template class.
  
  The base forecaster specifies the methods and method signatures that all forecasters
  have to implement.
  
  Specific implementations of these methods is deferred to concrete forecasters.
class_docstr_tok: ["Base","forecaster","template","class",".","The","base","forecaster","specifies","the","methods","and","method","signatures","that","all","forecasters","have","to","implement",".","Specific","implementations","of","these","methods","is","deferred","to","concrete","forecasters","."]
docstr: Return residuals of time series forecasts.
  
  Residuals will be computed for forecasts at y.index.
  
  If fh must be passed in fit, must agree with y.index.
  If y is an np.ndarray, and no fh has been passed in fit,
  the residuals will be computed at a fh of range(len(y.shape[0]))
  
  State required:
      Requires state to be "fitted".
      If fh has been set, must correspond to index of y (pandas or integer)
  
  Accesses in self:
      Fitted model attributes ending in "_".
      self.cutoff, self._is_fitted
  
  Writes to self:
      Nothing.
  
  Parameters
  ----------
  y : time series in sktime compatible data container format
      Time series with ground truth observations, to compute residuals to.
      Must have same type, dimension, and indices as expected return of predict.
      if None, the y seen so far (self._y) are used, in particular:
          if preceded by a single fit call, then in-sample residuals are produced
          if fit requires fh, it must have pointed to index of y in fit
  X : pd.DataFrame, or 2D np.ndarray, optional (default=None)
      Exogeneous time series to predict from
      if self.get_tag("X-y-must-have-same-index"),
          X.index must contain fh.index and y.index both
  
  Returns
  -------
  y_res : time series in sktime compatible data container format
      Forecast residuals at fh, with same index as fh
      y_res has same type as the y that has been passed most recently:
          Series, Panel, Hierarchical scitype, same format (see above)
docstr_tok: ["Return","residuals","of","time","series","forecasts",".","Residuals","will","be","computed","for","forecasts","at","y.index",".","If","fh","must","be","passed","in","fit",",","must","agree","with","y.index",".","If","y","is","an","np.ndarray",",","and","no","fh","has","been","passed","in","fit",",","the","residuals","will","be","computed","at","a","fh","of","range","(","len","(","y.shape","[","0","]",")",")","State","required",":","Requires","state","to","be","``","fitted","''",".","If","fh","has","been","set",",","must","correspond","to","index","of","y","(","pandas","or","integer",")","Accesses","in","self",":","Fitted","model","attributes","ending","in","``","_","''",".","self.cutoff",",","self._is_fitted","Writes","to","self",":","Nothing",".","Parameters","--","--","--","--","--","y",":","time","series","in","sktime","compatible","data","container","format","Time","series","with","ground","truth","observations",",","to","compute","residuals","to",".","Must","have","same","type",",","dimension",",","and","indices","as","expected","return","of","predict",".","if","None",",","the","y","seen","so","far","(","self._y",")","are","used",",","in","particular",":","if","preceded","by","a","single","fit","call",",","then","in-sample","residuals","are","produced","if","fit","requires","fh",",","it","must","have","pointed","to","index","of","y","in","fit","X",":","pd.DataFrame",",","or","2D","np.ndarray",",","optional","(","default=None",")","Exogeneous","time","series","to","predict","from","if","self.get_tag","(","``","X-y-must-have-same-index","''",")",",","X.index","must","contain","fh.index","and","y.index","both","Returns","--","--","--","-","y_res",":","time","series","in","sktime","compatible","data","container","format","Forecast","residuals","at","fh",",","with","same","index","as","fh","y_res","has","same","type","as","the","y","that","has","been","passed","most","recently",":","Series",",","Panel",",","Hierarchical","scitype",",","same","format","(","see","above",")"]
code: def predict_residuals(self, y=None, X=None):
      """Return residuals of time series forecasts.
  
      Residuals will be computed for forecasts at y.index.
  
      If fh must be passed in fit, must agree with y.index.
      If y is an np.ndarray, and no fh has been passed in fit,
      the residuals will be computed at a fh of range(len(y.shape[0]))
  
      State required:
          Requires state to be "fitted".
          If fh has been set, must correspond to index of y (pandas or integer)
  
      Accesses in self:
          Fitted model attributes ending in "_".
          self.cutoff, self._is_fitted
  
      Writes to self:
          Nothing.
  
      Parameters
      ----------
      y : time series in sktime compatible data container format
          Time series with ground truth observations, to compute residuals to.
          Must have same type, dimension, and indices as expected return of predict.
          if None, the y seen so far (self._y) are used, in particular:
              if preceded by a single fit call, then in-sample residuals are produced
              if fit requires fh, it must have pointed to index of y in fit
      X : pd.DataFrame, or 2D np.ndarray, optional (default=None)
          Exogeneous time series to predict from
          if self.get_tag("X-y-must-have-same-index"),
              X.index must contain fh.index and y.index both
  
      Returns
      -------
      y_res : time series in sktime compatible data container format
          Forecast residuals at fh, with same index as fh
          y_res has same type as the y that has been passed most recently:
              Series, Panel, Hierarchical scitype, same format (see above)
      """
      self.check_is_fitted()
  
      # clone self._fh to avoid any side-effects to self due to calling _check_fh
      # and predict()
      if self._fh is not None:
          fh_orig = deepcopy(self._fh)
      else:
          fh_orig = None
  
      # if no y is passed, the so far observed y is used
      if y is None:
          y = self._y
  
      # we want residuals, so fh must be the index of y
      # if data frame: take directly from y
      # to avoid issues with _set_fh, we convert to relative if self.fh is
      if isinstance(y, (pd.DataFrame, pd.Series)):
          fh = ForecastingHorizon(
              y.index, is_relative=False, freq=self._cutoff
          )
          if self._fh is not None and self.fh.is_relative:
              fh = fh.to_relative(self._cutoff)
          fh = self._check_fh(fh)
      # if np.ndarray, rows are not indexed
      # so will be interpreted as range(len), or existing fh if it is stored
      elif isinstance(y, np.ndarray):
          if self._fh is None:
              fh = range(y.shape[0])
          else:
              fh = self.fh
      else:
          raise TypeError("y must be a supported Series mtype")
  
      y_pred = self.predict(fh=fh, X=X)
  
      if not type(y_pred) is type(y):
          y = convert_to(y, self._y_metadata["mtype"])
  
      y_res = y - y_pred
  
      # write fh back to self that was given before calling predict_residuals to
      # avoid side-effects
      self._fh = fh_orig
  
      return y_res
  
imports: from copy import deepcopy
  from itertools import product
  import numpy
  import pandas
  from sktime.base import BaseEstimator
  from sktime.datatypes import VectorizedDF, check_is_scitype, convert_to, get_cutoff, mtype_to_scitype, scitype_to_mtype, update_data
  from sktime.forecasting.base._fh import ForecastingHorizon
  from sktime.utils.datetime import _shift
  from sktime.utils.validation._dependencies import _check_estimator_deps
  from sktime.utils.validation.forecasting import check_alpha, check_cv, check_fh, check_X
  from sktime.utils.validation.series import check_equal_time_index
  from sktime.utils.warnings import warn
label_desc: Use image node_id 17 for calling the BaseForecaster obj's underlying member method code with example usage: obj.predict_residuals(y, X) and returns: y_res