class_docstr: A Pipenet object connects transformers, detectors and aggregators.
  
  Parameters
  ----------
  steps: dicts
      Components of the pipenet. Each key-value item represents a step (
      transformer, detector, or aggregator), where key is the unique name of
      the step and the value is a dict with the following key-value pairs:
  
          - input (str or list of str): Input to the model, which must be
            either 'original' (i.e. the input time series), or the name of
            a upstream component.
          - subset (str, list of str, or list of lists of str, optional): If
            a model does not use all series from an input component, use this
            field to specify which series should be included. If not given or
            "all", all series from the input component will be used.
          - model (object): A detector, transformer, or aggregator object.
  
  Attributes
  ----------
  steps_graph_: OrderedDict
      Order of steps to be executed. Keys are step names, values are 2-tuple
      (i, j) where i is the index of execution round and j is the the index
      within a round.
  
  final_step_: str
      Name of the final step to be executed. It is the single step in the
      last round of execution in attribute `steps_graph_`.
  
  Examples
  --------
  The following example show how to use a Pipenet to build a level shift
  detector with some basic transformers, detectors, and aggregator.
  
  >>> from adtk.detector import QuantileAD, ThresholdAD
  >>> from adtk.transformer import DoubleRollingAggregate
  >>> from adtk.aggregator import AndAggregator
  >>> from adtk.pipe import Pipenet
  >>> steps = {
          "diff_abs": {
              "input": "original",
              "model": DoubleRollingAggregate(
                  agg="median",
                  window=20,
                  center=True,
                  diff="l1",
              ),
          },
          "quantile_ad": {
              "input": "diff_abs",
              "model": QuantileAD(high=0.99, low=0),
          },
          "diff": {
              "input": "original",
              "model": DoubleRollingAggregate(
                  agg="median",
                  window=20,
                  center=True,
                  diff="diff",
              ),
          },
          "sign_check": {
              "input": "diff",
              "model": ThresholdAD(high=0.0, low=-float("inf")),
          },
          "and": {
              "model": AndAggregator(),
              "input": ["quantile_ad", "sign_check"],
          },
      }
  >>> myPipenet = Pipenet(steps)
docstr: Train models in the pipenet.
  
  Parameters
  ----------
  ts: pandas Series or DataFrame
      Time series used to train models.
  
  skip_fit: list, optional
      Models to skip training. This could be used when pipenet contains
      models that are already trained by the same time series, and re-
      training would be time consuming. It must be a list of strings
      where each element is a model name. Default: None.
  
  return_intermediate: bool, optional
      Whether to return intermediate results. Default: False.
  
  Returns
  -------
  dict, optional
      If return_intermediate=True, return intermediate results generated
      during training as a dictionary where keys are step names. If a
      step does not perform transformation or detection, the result of
      that step will be None.
docstr_tok: ["Train","models","in","the","pipenet",".","Parameters","--","--","--","--","--","ts",":","pandas","Series","or","DataFrame","Time","series","used","to","train","models",".","skip_fit",":","list",",","optional","Models","to","skip","training",".","This","could","be","used","when","pipenet","contains","models","that","are","already","trained","by","the","same","time","series",",","and","re-","training","would","be","time","consuming",".","It","must","be","a","list","of","strings","where","each","element","is","a","model","name",".","Default",":","None",".","return_intermediate",":","bool",",","optional","Whether","to","return","intermediate","results",".","Default",":","False",".","Returns","--","--","--","-","dict",",","optional","If","return_intermediate=True",",","return","intermediate","results","generated","during","training","as","a","dictionary","where","keys","are","step","names",".","If","a","step","does","not","perform","transformation","or","detection",",","the","result","of","that","step","will","be","None","."]
code: def fit(
      self,
      ts: Union[pd.Series, pd.DataFrame],
      skip_fit: Optional[List[str]] = None,
      return_intermediate: bool = False,
  ) -> Optional[Dict[str, Optional[Union[pd.Series, pd.DataFrame]]]]:
      """Train models in the pipenet.
  
      Parameters
      ----------
      ts: pandas Series or DataFrame
          Time series used to train models.
  
      skip_fit: list, optional
          Models to skip training. This could be used when pipenet contains
          models that are already trained by the same time series, and re-
          training would be time consuming. It must be a list of strings
          where each element is a model name. Default: None.
  
      return_intermediate: bool, optional
          Whether to return intermediate results. Default: False.
  
      Returns
      -------
      dict, optional
          If return_intermediate=True, return intermediate results generated
          during training as a dictionary where keys are step names. If a
          step does not perform transformation or detection, the result of
          that step will be None.
  
      """
      self._validate()
  
      if skip_fit is None:
          skip_fit = []
      if not isinstance(skip_fit, list):
          raise TypeError("Parameter `skip_fit` must be a list.")
      if not set(skip_fit) <= set(self.steps.keys()):
          raise ValueError(
              "Name(s) in `skip_fit` is not valid model name."
          )
  
      # determine the step needing fit and/or predict
      need_fit = {
          step_name: (
              isinstance(step["model"], _TrainableModel)
              & (step_name not in skip_fit)
          )
          for step_name, step in self.steps.items()
      }
      need_predict = {
          step_name: False for step_name in self.steps.keys()
      }
      for step_name in list(self.steps_graph_.keys())[:0:-1]:
          if need_fit[step_name] or need_predict[step_name]:
              if isinstance(self.steps[step_name]["input"], str):
                  input = self.steps[step_name]["input"]
                  if input != "original":
                      need_predict[input] = True
              else:
                  for input in self.steps[step_name]["input"]:
                      if input != "original":
                          need_predict[input] = True
  
      # run fit or fit_predict
      results = {"original": ts.copy()}
      for step_name in list(self.steps_graph_.keys())[1:]:
          step = self.steps[step_name]
          if not (need_fit[step_name] or need_predict[step_name]):
              results.update({step_name: None})
              continue
          input = self._get_input(step, results)
          if need_fit[step_name] and (not need_predict[step_name]):
              step["model"].fit(input)
              results.update({step_name: None})
          elif (not need_fit[step_name]) and need_predict[step_name]:
              results.update({step_name: step["model"].predict(input)})
          else:
              results.update(
                  {step_name: step["model"].fit_predict(input)}
              )
  
      # return intermediate results
      if return_intermediate:
          return results
      else:
          return None
  
imports: from collections import OrderedDict
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import matplotlib.pyplot
  import pandas
  from matplotlib.collections import PatchCollection
  from matplotlib.lines import Line2D
  from matplotlib.patches import Circle
  from tabulate import tabulate
  from .._aggregator_base import _Aggregator
  from .._base import _Model, _TrainableModel
  from .._detector_base import _NonTrainableUnivariateDetector, _TrainableMultivariateDetector, _TrainableUnivariateDetector
  from .._transformer_base import _NonTrainableMultivariateTransformer, _NonTrainableUnivariateTransformer, _TrainableMultivariateTransformer, _TrainableUnivariateTransformer
  from ..metrics import f1_score, iou, precision, recall
label_desc: Use image node_id 4 for calling the Pipenet obj's underlying member method code with example usage: obj.fit(ts, skip_fit, return_intermediate) and returns: results, None