class_docstr: Hierarchical reconciliation forecaster.
  
  Reconciliation is applied to make the forecasts in a hierarchy of
  time-series sum together appropriately.
  
  The base forecasts are first generated for each member separately in the
  hierarchy using any forecaster. The base forecasts are then reonciled
  so that they sum together appropriately. This reconciliation step can often
  improve the skill of the forecasts in the hierarchy.
  
  Please refer to [1]_ for further information.
  
  Parameters
  ----------
  forecaster : estimator
      Estimator to generate base forecasts which are then reconciled
  method : {"mint_cov", "mint_shrink", "ols", "wls_var", "wls_str",             "bu", "td_fcst"}, default="mint_shrink"
      The reconciliation approach applied to the forecasts based on:
          * "mint_cov" - sample covariance
          * "mint_shrink" - covariance with shrinkage
          * "ols" - ordinary least squares
          * "wls_var" - weighted least squares (variance)
          * "wls_str" - weighted least squares (structural)
          * "bu" - bottom-up
          * "td_fcst" - top down based on forecast proportions
  
  See Also
  --------
  Aggregator
  Reconciler
  
  References
  ----------
  .. [1] https://otexts.com/fpp3/hierarchical.html
  
  Examples
  --------
  >>> from sktime.forecasting.naive import NaiveForecaster
  >>> from sktime.forecasting.reconcile import ReconcilerForecaster
  >>> from sktime.transformations.hierarchical.aggregate import Aggregator
  >>> from sktime.utils._testing.hierarchical import _bottom_hier_datagen
  >>> agg = Aggregator()
  >>> y = _bottom_hier_datagen(
  ...     no_bottom_nodes=3,
  ...     no_levels=1,
  ...     random_seed=123,
  ...     length=7,
  ... )
  >>> y = agg.fit_transform(y)
  >>> forecaster = NaiveForecaster(strategy="drift")
  >>> reconciler = ReconcilerForecaster(forecaster, method="mint_shrink")
  >>> reconciler.fit(y)
  ReconcilerForecaster(...)
  >>> prds_recon = reconciler.predict(fh=[1])
class_docstr_tok: ["Hierarchical","reconciliation","forecaster",".","Reconciliation","is","applied","to","make","the","forecasts","in","a","hierarchy","of","time-series","sum","together","appropriately",".","The","base","forecasts","are","first","generated","for","each","member","separately","in","the","hierarchy","using","any","forecaster",".","The","base","forecasts","are","then","reonciled","so","that","they","sum","together","appropriately",".","This","reconciliation","step","can","often","improve","the","skill","of","the","forecasts","in","the","hierarchy",".","Please","refer","to","[","1","]","_","for","further","information",".","Parameters","--","--","--","--","--","forecaster",":","estimator","Estimator","to","generate","base","forecasts","which","are","then","reconciled","method",":","{","``","mint_cov","''",",","``","mint_shrink","''",",","``","ols","''",",","``","wls_var","''",",","``","wls_str","''",",","``","bu","''",",","``","td_fcst","''","}",",","default=","''","mint_shrink","''","The","reconciliation","approach","applied","to","the","forecasts","based","on",":","*","``","mint_cov","''","-","sample","covariance","*","``","mint_shrink","''","-","covariance","with","shrinkage","*","``","ols","''","-","ordinary","least","squares","*","``","wls_var","''","-","weighted","least","squares","(","variance",")","*","``","wls_str","''","-","weighted","least","squares","(","structural",")","*","``","bu","''","-","bottom-up","*","``","td_fcst","''","-","top","down","based","on","forecast","proportions","See","Also","--","--","--","--","Aggregator","Reconciler","References","--","--","--","--","--","..","[","1","]","https",":","\/\/otexts.com\/fpp3\/hierarchical.html","Examples","--","--","--","--",">",">",">","from","sktime.forecasting.naive","import","NaiveForecaster",">",">",">","from","sktime.forecasting.reconcile","import","ReconcilerForecaster",">",">",">","from","sktime.transformations.hierarchical.aggregate","import","Aggregator",">",">",">","from","sktime.utils._testing.hierarchical","import","_bottom_hier_datagen",">",">",">","agg","=","Aggregator","(",")",">",">",">","y","=","_bottom_hier_datagen","(","...","no_bottom_nodes=3",",","...","no_levels=1",",","...","random_seed=123",",","...","length=7",",","...",")",">",">",">","y","=","agg.fit_transform","(","y",")",">",">",">","forecaster","=","NaiveForecaster","(","strategy=","''","drift","''",")",">",">",">","reconciler","=","ReconcilerForecaster","(","forecaster",",","method=","''","mint_shrink","''",")",">",">",">","reconciler.fit","(","y",")","ReconcilerForecaster","(","...",")",">",">",">","prds_recon","=","reconciler.predict","(","fh=","[","1","]",")"]
docstr: Define the G matrix for the MinT methods based on model residuals.
  
  Reconciliation methods require the G matrix. The G matrix is used to redefine
  base forecasts for the entire hierarchy to the bottom-level only before
  summation using the S matrix.
  
  Please refer to [1]_ for further information.
  
  Parameters
  ----------
  shrink:  bool, optional (default=False)
      Shrink the off diagonal elements of the sample covariance matrix.
      according to the method in [2]_
  diag_only: bool, optional (default=False)
      Remove the off-diagonal elements of the sample covariance matrix.
  
  Returns
  -------
  g_mint : pd.DataFrame with rows equal to the number of bottom level nodes
      only, i.e. with no aggregate nodes, and columns equal to the number of
      unique nodes in the hierarchy. The matrix indexes is inherited from the
      input data, with the time level removed.
  
  References
  ----------
  .. [1] https://otexts.com/fpp3/hierarchical.html
  .. [2] https://doi.org/10.2202/1544-6115.1175
docstr_tok: ["Define","the","G","matrix","for","the","MinT","methods","based","on","model","residuals",".","Reconciliation","methods","require","the","G","matrix",".","The","G","matrix","is","used","to","redefine","base","forecasts","for","the","entire","hierarchy","to","the","bottom-level","only","before","summation","using","the","S","matrix",".","Please","refer","to","[","1","]","_","for","further","information",".","Parameters","--","--","--","--","--","shrink",":","bool",",","optional","(","default=False",")","Shrink","the","off","diagonal","elements","of","the","sample","covariance","matrix",".","according","to","the","method","in","[","2","]","_","diag_only",":","bool",",","optional","(","default=False",")","Remove","the","off-diagonal","elements","of","the","sample","covariance","matrix",".","Returns","--","--","--","-","g_mint",":","pd.DataFrame","with","rows","equal","to","the","number","of","bottom","level","nodes","only",",","i.e",".","with","no","aggregate","nodes",",","and","columns","equal","to","the","number","of","unique","nodes","in","the","hierarchy",".","The","matrix","indexes","is","inherited","from","the","input","data",",","with","the","time","level","removed",".","References","--","--","--","--","--","..","[","1","]","https",":","\/\/otexts.com\/fpp3\/hierarchical.html","..","[","2","]","https",":","\/\/doi.org\/10.2202\/1544-6115.1175"]
code: def _get_g_matrix_mint(self, shrink=False, diag_only=False):
      """Define the G matrix for the MinT methods based on model residuals.
  
      Reconciliation methods require the G matrix. The G matrix is used to redefine
      base forecasts for the entire hierarchy to the bottom-level only before
      summation using the S matrix.
  
      Please refer to [1]_ for further information.
  
      Parameters
      ----------
      shrink:  bool, optional (default=False)
          Shrink the off diagonal elements of the sample covariance matrix.
          according to the method in [2]_
      diag_only: bool, optional (default=False)
          Remove the off-diagonal elements of the sample covariance matrix.
  
      Returns
      -------
      g_mint : pd.DataFrame with rows equal to the number of bottom level nodes
          only, i.e. with no aggregate nodes, and columns equal to the number of
          unique nodes in the hierarchy. The matrix indexes is inherited from the
          input data, with the time level removed.
  
      References
      ----------
      .. [1] https://otexts.com/fpp3/hierarchical.html
      .. [2] https://doi.org/10.2202/1544-6115.1175
      """
      if self.residuals_.index.nlevels < 2:
          return None
  
      # copy for further mods
      resid = self.residuals_.copy()
      resid = resid.unstack().transpose()
      cov_mat = resid.cov()
  
      if shrink:
          # diag matrix of variances
          var_d = pd.DataFrame(
              0.0, index=cov_mat.index, columns=cov_mat.columns
          )
          np.fill_diagonal(var_d.values, np.diag(cov_mat))
  
          # get correltion from covariance above
          cor_mat = resid.corr()
          nobs = len(resid)
  
          # first standardize the residuals
          resid = resid.apply(lambda x: (x - x.mean()) / x.std())
  
          # scale for higher order var calc
          scale_hovar = ((resid.transpose().dot(resid)) ** 2) * (
              1 / nobs
          )
  
          # higherorder var (only diags)
          resid_corseries = resid**2
          hovar_mat = (
              resid_corseries.transpose().dot(resid_corseries)
          ) - scale_hovar
          hovar_mat = (nobs / (nobs - 1) ** 3) * hovar_mat
  
          # set diagonals to zero
          for i in resid.columns:
              hovar_mat.loc[
                  hovar_mat.index == i, hovar_mat.columns == i
              ] = 0
              cor_mat.loc[cor_mat.index == i, cor_mat.columns == i] = 0
  
          # get the shrinkage value
          lamb = hovar_mat.sum().sum() / (cor_mat**2).sum().sum()
          lamb = np.min([1, np.max([0, lamb])])
  
          # shrink the matrix
          cov_mat = (lamb * var_d) + ((1 - lamb) * cov_mat)
  
      if diag_only:
          # digonal matrix of variances
          for i in resid.columns:
              cov_mat.loc[cov_mat.index != i, cov_mat.columns == i] = 0
  
      # now get the g matrix based on the covariance
      g_mint = pd.DataFrame(
          np.dot(
              inv(
                  np.dot(
                      np.transpose(self.s_matrix),
                      np.dot(cov_mat, self.s_matrix),
                  )
              ),
              np.dot(np.transpose(self.s_matrix), cov_mat),
          )
      )
      # set indexes of matrix
      g_mint = g_mint.transpose()
      g_mint = g_mint.set_index(self.s_matrix.index)
      g_mint.columns = self.s_matrix.columns
      g_mint = g_mint.transpose()
  
      return g_mint
  
file_path: sktime/sktime/forecasting/reconcile.py
imports: import numpy
  import pandas
  from numpy.linalg import inv
  from sktime.forecasting.base import BaseForecaster, ForecastingHorizon
  from sktime.transformations.hierarchical.aggregate import _check_index_no_total
  from sktime.transformations.hierarchical.reconcile import Reconciler, _get_s_matrix, _parent_child_df
  from sktime.utils.warnings import warn
label_desc: Use image node_id 6 for calling the ReconcilerForecaster obj's underlying member method code with example usage: obj._get_g_matrix_mint(shrink, diag_only) and returns: g_mint, None