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: Compute/return variance forecasts.
  
  private _predict_var containing the core logic, called from predict_var
  
  Parameters
  ----------
  fh : guaranteed to be ForecastingHorizon
      The forecasting horizon with the steps ahead to to predict.
  X : optional (default=None)
      guaranteed to be of a type in self.get_tag("X_inner_mtype")
      Exogeneous time series to predict from.
  cov : bool, optional (default=False)
      if True, computes covariance matrix forecast.
      if False, computes marginal variance forecasts.
  
  Returns
  -------
  pred_var : pd.DataFrame, format dependent on `cov` variable
      If cov=False:
          Column names are exactly those of `y` passed in `fit`/`update`.
              For nameless formats, column index will be a RangeIndex.
          Row index is fh, with additional levels equal to instance levels,
              from y seen in fit, if y_inner_mtype is Panel or Hierarchical.
          Entries are variance forecasts, for var in col index.
          A variance forecast for given variable and fh index is a predicted
              variance for that variable and index, given observed data.
      If cov=True:
          Column index is a multiindex: 1st level is variable names (as above)
              2nd level is fh.
          Row index is fh, with additional levels equal to instance levels,
              from y seen in fit, if y_inner_mtype is Panel or Hierarchical.
          Entries are (co-)variance forecasts, for var in col index, and
              covariance between time index in row and col.
          Note: no covariance forecasts are returned between different variables.
docstr_tok: ["Compute\/return","variance","forecasts",".","private","_predict_var","containing","the","core","logic",",","called","from","predict_var","Parameters","--","--","--","--","--","fh",":","guaranteed","to","be","ForecastingHorizon","The","forecasting","horizon","with","the","steps","ahead","to","to","predict",".","X",":","optional","(","default=None",")","guaranteed","to","be","of","a","type","in","self.get_tag","(","``","X_inner_mtype","''",")","Exogeneous","time","series","to","predict","from",".","cov",":","bool",",","optional","(","default=False",")","if","True",",","computes","covariance","matrix","forecast",".","if","False",",","computes","marginal","variance","forecasts",".","Returns","--","--","--","-","pred_var",":","pd.DataFrame",",","format","dependent","on","`","cov","`","variable","If","cov=False",":","Column","names","are","exactly","those","of","`","y","`","passed","in","`","fit","`","\/","`","update","`",".","For","nameless","formats",",","column","index","will","be","a","RangeIndex",".","Row","index","is","fh",",","with","additional","levels","equal","to","instance","levels",",","from","y","seen","in","fit",",","if","y_inner_mtype","is","Panel","or","Hierarchical",".","Entries","are","variance","forecasts",",","for","var","in","col","index",".","A","variance","forecast","for","given","variable","and","fh","index","is","a","predicted","variance","for","that","variable","and","index",",","given","observed","data",".","If","cov=True",":","Column","index","is","a","multiindex",":","1st","level","is","variable","names","(","as","above",")","2nd","level","is","fh",".","Row","index","is","fh",",","with","additional","levels","equal","to","instance","levels",",","from","y","seen","in","fit",",","if","y_inner_mtype","is","Panel","or","Hierarchical",".","Entries","are","(","co-",")","variance","forecasts",",","for","var","in","col","index",",","and","covariance","between","time","index","in","row","and","col",".","Note",":","no","covariance","forecasts","are","returned","between","different","variables","."]
code: def _predict_var(self, fh=None, X=None, cov=False):
      """Compute/return variance forecasts.
  
      private _predict_var containing the core logic, called from predict_var
  
      Parameters
      ----------
      fh : guaranteed to be ForecastingHorizon
          The forecasting horizon with the steps ahead to to predict.
      X : optional (default=None)
          guaranteed to be of a type in self.get_tag("X_inner_mtype")
          Exogeneous time series to predict from.
      cov : bool, optional (default=False)
          if True, computes covariance matrix forecast.
          if False, computes marginal variance forecasts.
  
      Returns
      -------
      pred_var : pd.DataFrame, format dependent on `cov` variable
          If cov=False:
              Column names are exactly those of `y` passed in `fit`/`update`.
                  For nameless formats, column index will be a RangeIndex.
              Row index is fh, with additional levels equal to instance levels,
                  from y seen in fit, if y_inner_mtype is Panel or Hierarchical.
              Entries are variance forecasts, for var in col index.
              A variance forecast for given variable and fh index is a predicted
                  variance for that variable and index, given observed data.
          If cov=True:
              Column index is a multiindex: 1st level is variable names (as above)
                  2nd level is fh.
              Row index is fh, with additional levels equal to instance levels,
                  from y seen in fit, if y_inner_mtype is Panel or Hierarchical.
              Entries are (co-)variance forecasts, for var in col index, and
                  covariance between time index in row and col.
              Note: no covariance forecasts are returned between different variables.
      """
      from scipy.stats import norm
  
      # default behaviour is implemented if one of the following three is implemented
      implements_interval = self._has_implementation_of(
          "_predict_interval"
      )
      implements_quantiles = self._has_implementation_of(
          "_predict_quantiles"
      )
      implements_proba = self._has_implementation_of("_predict_proba")
      can_do_proba = (
          implements_interval
          or implements_quantiles
          or implements_proba
      )
  
      if not can_do_proba:
          raise RuntimeError(
              f"{self.__class__.__name__} does not implement "
              "probabilistic forecasting, "
              'but "capability:pred_int" flag has been set to True incorrectly. '
              "This is likely a bug, please report, and/or set the flag to False."
          )
  
      if implements_proba:
          # todo: this works only univariate now, need to implement multivariate
          pred_var = self._predict_proba(fh=fh, X=X)
          pred_var = pd.DataFrame(pred_var)
  
          # ensure index and columns are as expected
          if fh.is_relative:
              fh = fh.to_absolute(self.cutoff)
          pred_var.index = fh.to_pandas()
  
          if isinstance(self._y, pd.DataFrame):
              pred_var.columns = self._get_columns(method="predict_var")
  
          return pred_var
  
      # if has one of interval/quantile predictions implemented:
      #   we get quantile forecasts for first and third quartile
      #   return variance of normal distribution with that first and third quartile
      if implements_interval or implements_quantiles:
          pred_int = self._predict_interval(fh=fh, X=X, coverage=[0.5])
          var_names = pred_int.columns.get_level_values(0).unique()
          vars_dict = {}
          for i in var_names:
              pred_int_i = pred_int[i].copy()
              # compute inter-quartile range (IQR), as pd.Series
              iqr_i = pred_int_i.iloc[:, 1] - pred_int_i.iloc[:, 0]
              # dividing by IQR of normal gives std of normal with same IQR
              std_i = iqr_i / (2 * norm.ppf(0.75))
              # and squaring gives variance (pd.Series)
              var_i = std_i**2
              vars_dict[i] = var_i
  
          # put together to pd.DataFrame
          #   the indices and column names are already correct
          pred_var = pd.DataFrame(vars_dict)
  
      return pred_var
  
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 36 for calling the BaseForecaster obj's underlying member method code with example usage: obj._predict_var(fh, X, cov) and returns: pred_var, pred_var