class_docstr: Hierarchical agglomerative estimation of multiple change points.
  
  E-Agglo is a non-parametric clustering approach for multivariate timeseries[1]_,
  where neighboring segments are sequentially merged_ to maximize a goodness-of-fit
  statistic. Unlike most general purpose agglomerative clustering algorithms, this
  procedure preserves the time ordering of the observations.
  
  This method can detect distributional change within an independent sequence,
  and does not make any distributional assumptions (beyond the existence of an
  alpha-th moment). Estimation is performed in a manner that simultaneously
  identifies both the number and locations of change points.
  
  Parameters
  ----------
  member : array_like (default=None)
      Assigns points to to the initial cluster membership, therefore the first
      dimension should be the same as for data. If `None` it will be initialized
      to dummy vector where each point is assigned to separate cluster.
  alpha : float (default=1.0)
      Fixed constant alpha in (0, 2] used in the divergence measure, as the
      alpha-th absolute moment, see equation (4) in [1]_.
  penalty : str or callable or None (default=None)
      Function that defines a penalization of the sequence of goodness-of-fit
      statistic, when overfitting is a concern. If `None` not penalty is applied.
      Could also be an existing penalty name, either `len_penalty` or
      `mean_diff_penalty`.
  
  Attributes
  ----------
  merged_ : array_like
      2D `array_like` outlining which clusters were merged_ at each step.
  gof_ : float
      goodness-of-fit statistic for current clsutering.
  cluster_ : array_like
      1D `array_like` specifying which cluster each row of input data
      X belongs to.
  
  Notes
  -----
  Based on the work from [1]_.
  
  - source code based on: https://github.com/cran/ecp/blob/master/R/e_agglomerative.R
  - paper available at: https://www.tandfonline.com/doi/full/10.1080/01621459.        2013.849605
  
  References
  ----------
  .. [1] Matteson, David S., and Nicholas A. James. "A nonparametric approach for
  multiple change point analysis of multivariate data." Journal of the American
  Statistical Association 109.505 (2014): 334-345.
  
  .. [2] James, Nicholas A., and David S. Matteson. "ecp: An R package for
  nonparametric multiple change point analysis of multivariate data." arXiv preprint
  arXiv:1309.3295 (2013).
  
  Examples
  --------
  >>> from sktime.annotation.datagen import piecewise_normal_multivariate
  >>> X = piecewise_normal_multivariate(means=[[1, 3], [4, 5]], lengths=[3, 4],
  ... random_state = 10)
  >>> from sktime.annotation.eagglo import EAgglo
  >>> model = EAgglo()
  >>> model.fit_transform(X)
  array([0, 0, 0, 1, 1, 1, 1])
class_docstr_tok: ["Hierarchical","agglomerative","estimation","of","multiple","change","points",".","E-Agglo","is","a","non-parametric","clustering","approach","for","multivariate","timeseries","[","1","]","_",",","where","neighboring","segments","are","sequentially","merged_","to","maximize","a","goodness-of-fit","statistic",".","Unlike","most","general","purpose","agglomerative","clustering","algorithms",",","this","procedure","preserves","the","time","ordering","of","the","observations",".","This","method","can","detect","distributional","change","within","an","independent","sequence",",","and","does","not","make","any","distributional","assumptions","(","beyond","the","existence","of","an","alpha-th","moment",")",".","Estimation","is","performed","in","a","manner","that","simultaneously","identifies","both","the","number","and","locations","of","change","points",".","Parameters","--","--","--","--","--","member",":","array_like","(","default=None",")","Assigns","points","to","to","the","initial","cluster","membership",",","therefore","the","first","dimension","should","be","the","same","as","for","data",".","If","`","None","`","it","will","be","initialized","to","dummy","vector","where","each","point","is","assigned","to","separate","cluster",".","alpha",":","float","(","default=1.0",")","Fixed","constant","alpha","in","(","0",",","2","]","used","in","the","divergence","measure",",","as","the","alpha-th","absolute","moment",",","see","equation","(","4",")","in","[","1","]","_.","penalty",":","str","or","callable","or","None","(","default=None",")","Function","that","defines","a","penalization","of","the","sequence","of","goodness-of-fit","statistic",",","when","overfitting","is","a","concern",".","If","`","None","`","not","penalty","is","applied",".","Could","also","be","an","existing","penalty","name",",","either","`","len_penalty","`","or","`","mean_diff_penalty","`",".","Attributes","--","--","--","--","--","merged_",":","array_like","2D","`","array_like","`","outlining","which","clusters","were","merged_","at","each","step",".","gof_",":","float","goodness-of-fit","statistic","for","current","clsutering",".","cluster_",":","array_like","1D","`","array_like","`","specifying","which","cluster","each","row","of","input","data","X","belongs","to",".","Notes","--","--","-","Based","on","the","work","from","[","1","]","_",".","-","source","code","based","on",":","https",":","\/\/github.com\/cran\/ecp\/blob\/master\/R\/e_agglomerative.R","-","paper","available","at",":","https",":","\/\/www.tandfonline.com\/doi\/full\/10.1080\/01621459",".","2013.849605","References","--","--","--","--","--","..","[","1","]","Matteson",",","David","S.",",","and","Nicholas","A.","James",".","``","A","nonparametric","approach","for","multiple","change","point","analysis","of","multivariate","data",".","''","Journal","of","the","American","Statistical","Association","109.505","(","2014",")",":","334-345",".","..","[","2","]","James",",","Nicholas","A.",",","and","David","S.","Matteson",".","``","ecp",":","An","R","package","for","nonparametric","multiple","change","point","analysis","of","multivariate","data",".","''","arXiv","preprint","arXiv:1309.3295","(","2013",")",".","Examples","--","--","--","--",">",">",">","from","sktime.annotation.datagen","import","piecewise_normal_multivariate",">",">",">","X","=","piecewise_normal_multivariate","(","means=","[","[","1",",","3","]",",","[","4",",","5","]","]",",","lengths=","[","3",",","4","]",",","...","random_state","=","10",")",">",">",">","from","sktime.annotation.eagglo","import","EAgglo",">",">",">","model","=","EAgglo","(",")",">",">",">","model.fit_transform","(","X",")","array","(","[","0",",","0",",","0",",","1",",","1",",","1",",","1","]",")"]
docstr: Find optimally clustered segments.
  
  First, by determining which pairs of adjacent clusters will be merged_. Then,
  this process is repeated, recording the goodness-of-fit statistic at each step,
  until all observations belong to a single cluster. Finally, the estimated number
  of change points is estimated by the clustering that maximizes the goodness-of-
  fit statistic over the entire merging sequence.
  
  Parameters
  ----------
  X : pd.DataFrame
      Data for anomaly detection (time series).
  y : pd.Series, optional
      Not used for this unsupervsed method.
  
  Returns
  -------
  self :
      Reference to self.
docstr_tok: ["Find","optimally","clustered","segments",".","First",",","by","determining","which","pairs","of","adjacent","clusters","will","be","merged_",".","Then",",","this","process","is","repeated",",","recording","the","goodness-of-fit","statistic","at","each","step",",","until","all","observations","belong","to","a","single","cluster",".","Finally",",","the","estimated","number","of","change","points","is","estimated","by","the","clustering","that","maximizes","the","goodness-of-","fit","statistic","over","the","entire","merging","sequence",".","Parameters","--","--","--","--","--","X",":","pd.DataFrame","Data","for","anomaly","detection","(","time","series",")",".","y",":","pd.Series",",","optional","Not","used","for","this","unsupervsed","method",".","Returns","--","--","--","-","self",":","Reference","to","self","."]
code: def _fit(self, X: pd.DataFrame, y=None):
      """Find optimally clustered segments.
  
      First, by determining which pairs of adjacent clusters will be merged_. Then,
      this process is repeated, recording the goodness-of-fit statistic at each step,
      until all observations belong to a single cluster. Finally, the estimated number
      of change points is estimated by the clustering that maximizes the goodness-of-
      fit statistic over the entire merging sequence.
  
      Parameters
      ----------
      X : pd.DataFrame
          Data for anomaly detection (time series).
      y : pd.Series, optional
          Not used for this unsupervsed method.
  
      Returns
      -------
      self :
          Reference to self.
      """
      self._X = X
  
      if self.alpha <= 0 or self.alpha > 2:
          raise ValueError(
              f"allowed values for 'alpha' are (0, 2], got: {self.alpha}"
          )
  
      self._initialize_params(X)
  
      # find which clusters optimize the gof_ and then update the distances
      for K in range(self.n_cluster - 1, 2 * self.n_cluster - 2):
          i, j = self._find_closest(K)
          self._update_distances(i, j, K)
  
      def filter_na(i):
          return list(
              filter(
                  lambda v: v == v,
                  self.progression[i,],
              )
          )
  
      # penalize the gof_ statistic
      if self.penalty is not None:
          penalty_func = self._get_penalty_func()
          cps = [filter_na(i) for i in range(len(self.progression))]
          self.gof_ += list(map(penalty_func, cps))
  
      # get the set of change points for the "best" clustering
      idx = np.argmax(self.gof_)
      self._estimates = np.sort(filter_na(idx))
  
      # remove change point N+1 if a cyclic merger was performed
      self._estimates = (
          self._estimates[:-1]
          if self._estimates[0] != 0
          else self._estimates
      )
  
      # create final membership vector
      def get_cluster(estimates):
          return np.repeat(
              range(len(np.diff(estimates))),
              np.diff(estimates).astype(int),
          )
  
      if self._estimates[0] == 0:
          self.cluster_ = get_cluster(self._estimates)
      else:
          tmp = get_cluster(np.append([0], self._estimates))
          self.cluster_ = np.append(
              tmp, np.zeros(X.shape[0] - len(tmp))
          )
  
      return self
  
imports: import warnings
  from typing import Callable, Dict, List, Tuple
  import numpy
  import pandas
  from scipy.spatial.distance import cdist
  from sktime.transformations.base import BaseTransformer
label_desc: Use image node_id 2 for calling the EAgglo obj's underlying member method code with example usage: obj._fit(X, y) and returns: self, list, np