class_docstr: Aggregates hierarchical data, fit forecasters and make predictions.
  
  Can apply different univariate forecaster either on different
  level of aggregation or on different hierarchical nodes.
  
  `HierarchyEnsembleForecaster` is passed forecaster/level or
  forecaster/node pairs. Level can only be int >= 0 with 0
  signifying the topmost level of aggregation.
  Node can only be a tuple of strings or list of tuples.
  
  Behaviour in `fit`, `predict`:
  For level pairs f_i, l_i passed, applies forecaster f_i to level l_i.
  For node pairs f_i, n_i passed, applies forecaster f_i on each node of n_i.
  if "default" argument passed, applies "default" forecaster on the
  remaining levels/nodes which are not mentioned in argument 'forecasters'.
  `predict` results are concatenated to one container with same columns as in `fit`.
  
  
  Parameters
  ----------
  forecasters : sktime forecaster, or list of tuples
              (str, estimator, int or list of tuple/s)
      if forecaster, clones of forecaster are applied to all aggregated levels.
      if list of tuples, with name = str, estimator is forecaster, level/node
      as int/tuples respectively.
      all levels/nodes must be present in 'forecasters' attribute if 'default'
      attribute is None
  
  by : {'node', 'level', default='level'}
      if 'level', applies a univariate forecaster on all the hierarchical
      nodes within a level of aggregation
      if 'node', applies separate univariate forecaster for each
      hierarchical node.
  
  default : sktime forecaster {default = None}
      if passed, applies 'default' forecaster on the nodes/levels
      not mentioned in the 'forecaster' argument.
  
  Examples
  --------
  >>> from sktime.forecasting.compose import HierarchyEnsembleForecaster
  >>> from sktime.forecasting.naive import NaiveForecaster
  >>> from sktime.forecasting.trend import PolynomialTrendForecaster, TrendForecaster
  >>> from sktime.utils._testing.hierarchical import _bottom_hier_datagen
  >>> y = _bottom_hier_datagen(
  ...         no_bottom_nodes=7,
  ...         no_levels=2,
  ...         random_seed=123
  ... )
  
  >>> # Example of by = 'level'
  >>> forecasters = [
  ...     ('naive', NaiveForecaster(), 0),
  ...     ('trend', TrendForecaster(), 1)
  ... ]
  >>> forecaster = HierarchyEnsembleForecaster(
  ...                 forecasters=forecasters,
  ...                 by='level', default = PolynomialTrendForecaster(degree=2)
  ... )
  >>> forecaster.fit(y, fh=[1, 2, 3])
  HierarchyEnsembleForecaster(...)
  >>> y_pred = forecaster.predict()
  
  >>> # Example of by = 'node'
  >>> forecasters = [
  ...     ('trend', TrendForecaster(), [("__total", "__total")]),
  ...     ('poly', PolynomialTrendForecaster(degree=2), [('l2_node01', 'l1_node01')]),
  ... ]
  >>> forecaster = HierarchyEnsembleForecaster(
  ...                 forecasters=forecasters,
  ...                 by='node', default=NaiveForecaster()
  ... )
  >>> forecaster.fit(y, fh=[1, 2, 3])
  HierarchyEnsembleForecaster(...)
  >>> y_pred = forecaster.predict()
class_docstr_tok: ["Aggregates","hierarchical","data",",","fit","forecasters","and","make","predictions",".","Can","apply","different","univariate","forecaster","either","on","different","level","of","aggregation","or","on","different","hierarchical","nodes",".","`","HierarchyEnsembleForecaster","`","is","passed","forecaster\/level","or","forecaster\/node","pairs",".","Level","can","only","be","int",">","=","0","with","0","signifying","the","topmost","level","of","aggregation",".","Node","can","only","be","a","tuple","of","strings","or","list","of","tuples",".","Behaviour","in","`","fit","`",",","`","predict","`",":","For","level","pairs","f_i",",","l_i","passed",",","applies","forecaster","f_i","to","level","l_i",".","For","node","pairs","f_i",",","n_i","passed",",","applies","forecaster","f_i","on","each","node","of","n_i",".","if","``","default","''","argument","passed",",","applies","``","default","''","forecaster","on","the","remaining","levels\/nodes","which","are","not","mentioned","in","argument","'forecasters","'",".","`","predict","`","results","are","concatenated","to","one","container","with","same","columns","as","in","`","fit","`",".","Parameters","--","--","--","--","--","forecasters",":","sktime","forecaster",",","or","list","of","tuples","(","str",",","estimator",",","int","or","list","of","tuple\/s",")","if","forecaster",",","clones","of","forecaster","are","applied","to","all","aggregated","levels",".","if","list","of","tuples",",","with","name","=","str",",","estimator","is","forecaster",",","level\/node","as","int\/tuples","respectively",".","all","levels\/nodes","must","be","present","in","'forecasters","'","attribute","if","'default'","attribute","is","None","by",":","{","'node","'",",","'level","'",",","default='level","'","}","if","'level","'",",","applies","a","univariate","forecaster","on","all","the","hierarchical","nodes","within","a","level","of","aggregation","if","'node","'",",","applies","separate","univariate","forecaster","for","each","hierarchical","node",".","default",":","sktime","forecaster","{","default","=","None","}","if","passed",",","applies","'default","'","forecaster","on","the","nodes\/levels","not","mentioned","in","the","'forecaster","'","argument",".","Examples","--","--","--","--",">",">",">","from","sktime.forecasting.compose","import","HierarchyEnsembleForecaster",">",">",">","from","sktime.forecasting.naive","import","NaiveForecaster",">",">",">","from","sktime.forecasting.trend","import","PolynomialTrendForecaster",",","TrendForecaster",">",">",">","from","sktime.utils._testing.hierarchical","import","_bottom_hier_datagen",">",">",">","y","=","_bottom_hier_datagen","(","...","no_bottom_nodes=7",",","...","no_levels=2",",","...","random_seed=123","...",")",">",">",">","#","Example","of","by","=","'level'",">",">",">","forecasters","=","[","...","(","'naive","'",",","NaiveForecaster","(",")",",","0",")",",","...","(","'trend","'",",","TrendForecaster","(",")",",","1",")","...","]",">",">",">","forecaster","=","HierarchyEnsembleForecaster","(","...","forecasters=forecasters",",","...","by='level","'",",","default","=","PolynomialTrendForecaster","(","degree=2",")","...",")",">",">",">","forecaster.fit","(","y",",","fh=","[","1",",","2",",","3","]",")","HierarchyEnsembleForecaster","(","...",")",">",">",">","y_pred","=","forecaster.predict","(",")",">",">",">","#","Example","of","by","=","'node'",">",">",">","forecasters","=","[","...","(","'trend","'",",","TrendForecaster","(",")",",","[","(","``","__total","''",",","``","__total","''",")","]",")",",","...","(","'poly","'",",","PolynomialTrendForecaster","(","degree=2",")",",","[","(","'l2_node01","'",",","'l1_node01","'",")","]",")",",","...","]",">",">",">","forecaster","=","HierarchyEnsembleForecaster","(","...","forecasters=forecasters",",","...","by='node","'",",","default=NaiveForecaster","(",")","...",")",">",">",">","forecaster.fit","(","y",",","fh=","[","1",",","2",",","3","]",")","HierarchyEnsembleForecaster","(","...",")",">",">",">","y_pred","=","forecaster.predict","(",")"]
docstr: Create dictionaries of nodes and forecasters linked with common key value.
  
  Parameters
  ----------
  z : pd-multiindex
      Data to be segregated to hierarchical nodes
  
  Returns
  -------
  node_dict : dict
              Dictionary with key as int and value as
              Index/MultiIndex
  frcstr_dict : dict
              Dictionary with key as int and value as
              forecaster
docstr_tok: ["Create","dictionaries","of","nodes","and","forecasters","linked","with","common","key","value",".","Parameters","--","--","--","--","--","z",":","pd-multiindex","Data","to","be","segregated","to","hierarchical","nodes","Returns","--","--","--","-","node_dict",":","dict","Dictionary","with","key","as","int","and","value","as","Index\/MultiIndex","frcstr_dict",":","dict","Dictionary","with","key","as","int","and","value","as","forecaster"]
code: def _get_node_dict(self, z):
      """Create dictionaries of nodes and forecasters linked with common key value.
  
      Parameters
      ----------
      z : pd-multiindex
          Data to be segregated to hierarchical nodes
  
      Returns
      -------
      node_dict : dict
                  Dictionary with key as int and value as
                  Index/MultiIndex
      frcstr_dict : dict
                  Dictionary with key as int and value as
                  forecaster
      """
      node_dict = {}
      frcstr_dict = {}
      nodes = []
      counter = 0
      zindex = z.index.droplevel(-1).unique()
  
      for _, forecaster, node in self.forecasters_:
          if z.index.nlevels == 2:
              mi = pd.Index(node)
              if counter == 0:
                  nodes = mi
              else:
                  # For nlevels = 2, 'nodes' is pd.Index object (L286)
                  nodes = nodes.append(mi)
          else:
              node_l = []
              for i in range(len(node)):
                  if (
                      isinstance(node[i], tuple)
                      and len(node[i]) == z.index.nlevels - 1
                  ):
                      node_l.append(node[i])
                  elif isinstance(node[i], str):
                      for ind in zindex:
                          if ind[0] == node[i]:
                              node_l.append(ind)
                  else:
                      for ind in zindex:
                          if ind[: len(node[i])] == node[i]:
                              node_l.append(ind)
  
              mi = pd.MultiIndex.from_tuples(
                  node_l, names=z.index.names[:-1]
              )
              nodes += node_l
          frcstr_dict[counter] = forecaster
          node_dict[counter] = mi
          counter += 1
  
      diff_nodes = z.index.droplevel(-1).unique().difference(nodes)
      if self.default and len(diff_nodes) > 0:
          frcstr_dict[counter] = self.default
          node_dict[counter] = diff_nodes
  
      return node_dict, frcstr_dict
  
file_path: sktime/sktime/forecasting/compose/_hierarchy_ensemble.py
imports: import pandas
  from sktime.base._meta import flatten
  from sktime.forecasting.base._base import BaseForecaster
  from sktime.forecasting.base._meta import _HeterogenousEnsembleForecaster
  from sktime.transformations.hierarchical.aggregate import _check_index_no_total
  from sktime.utils.warnings import warn
label_desc: Use image node_id 7 for calling the HierarchyEnsembleForecaster obj's underlying member method code with example usage: obj._get_node_dict(z) and returns: node_dict,  frcstr_dict