class_docstr: Clustered Subsample index generator.
  
  Generates cross-validation folds according used to create ``J``
  partitions of the data and ``v`` folds on each partition according to as
  per [#]_:
  
      1. Split ``X`` into ``J`` partitions
  
      2. For each partition:
  
          (a) For each fold ``v``, create train index of all idx not in ``v``
  
          (b) Concatenate all the fold ``v`` indices into a test index for
              fold ``v`` that spans all partitions
  
  
  Setting ``J = 1`` is equivalent to the :class:`FullIndexer`, which returns
  standard K-Fold train and test set indices.
  
  :class:`ClusteredSubsetIndex` uses a user-provided estimator to partition
  the data, in contrast to the :class:`SubsetIndex` generator, which
  partitions data into randomly into equal sizes.
  
  See Also
  --------
  :class:`FoldIndex`, :class:`BlendIndex`, :class:`SubsetIndex`
  
  References
  ----------
  .. [#] Sapp, S., van der Laan, M. J., & Canny, J. (2014). Subsemble: an
     ensemble method for combining subset-specific algorithm fits. Journal
     of Applied Statistics, 41(6), 1247-1259.
     http://doi.org/10.1080/02664763.2013.864263
  
  Parameters
  ----------
  partition_estimator : instance
      Estimator to use for clustering.
  
  partitions : int
      Number of partitions the estimator will create.
  
  folds : int (default = 2)
      Number of folds to create in each partition. ``folds`` can
      not be 1 if ``n_partition > 1``. Note that if ``folds = 1``,
      both the train and test set will index the full data.
  
  fit_estimator : bool (default = True)
      whether to fit the estimator separately before generating labels.
  
  attr : str (default = 'predict')
      the attribute to use for generating cluster membership labels.
  
  X : array-like of shape [n_samples,] , optional
      the training set to partition. The training label array is also,
      accepted, as only the first dimension is used. If ``X`` is not
      passed at instantiation, the ``fit`` method must be called before
      ``generate``, or ``X`` must be passed as an argument of
      ``generate``.
  
  raise_on_exception : bool (default = True)
      whether to warn on suspicious slices or raise an error.
  
  Examples
  --------
  >>> import numpy as np
  >>> from sklearn.cluster import KMeans
  >>> from mlens.index import ClusteredSubsetIndex
  >>>
  >>> km = KMeans(3, random_state=0)
  >>> X = np.arange(12).reshape(-1, 1); np.random.shuffle(X)
  >>> print("Data: {}".format(X.ravel()))
  >>>
  >>> s = ClusteredSubsetIndex(km)
  >>> s.fit(X)
  >>>
  >>> P = s.partition_estimator.predict(X)
  >>> print("cluster labels: {}".format(P))
  >>>
  >>> for j, i in enumerate(s.partition(as_array=True)):
  ...    print("partition ({}) index: {}, cluster labels: {}".format(i, j + 1, P[i]))
  >>>
  >>> for i in s.generate(as_array=True):
  ...     print("train fold index: {}, cluster labels: {}".format(i[0], P[i[0]]))
  Data: [ 8  7  5  2  4 10 11  1  3  6  9  0]
  cluster labels: [0 2 2 1 2 0 0 1 1 2 0 1]
  partition (1) index: [ 0  5  6 10], cluster labels: [0 0 0 0]
  partition (2) index: [ 3  7  8 11], cluster labels: [1 1 1 1]
  partition (3) index: [1 2 4 9], cluster labels: [2 2 2 2]
  train fold index: [0 3 5], cluster labels: [0 0 0]
  train fold index: [ 6 10], cluster labels: [0 0]
  train fold index: [2 7], cluster labels: [1 1]
  train fold index: [ 9 11], cluster labels: [1 1]
  train fold index: [1 4], cluster labels: [2 2]
  train fold index: [8], cluster labels: [2]
class_docstr_tok: ["Clustered","Subsample","index","generator",".","Generates","cross-validation","folds","according","used","to","create","``","J","``","partitions","of","the","data","and","``","v","``","folds","on","each","partition","according","to","as","per","[","#","]","_",":","1",".","Split","``","X","``","into","``","J","``","partitions","2",".","For","each","partition",":","(","a",")","For","each","fold","``","v","``",",","create","train","index","of","all","idx","not","in","``","v","``","(","b",")","Concatenate","all","the","fold","``","v","``","indices","into","a","test","index","for","fold","``","v","``","that","spans","all","partitions","Setting","``","J","=","1","``","is","equivalent","to","the",":","class",":","`","FullIndexer","`",",","which","returns","standard","K-Fold","train","and","test","set","indices",".",":","class",":","`","ClusteredSubsetIndex","`","uses","a","user-provided","estimator","to","partition","the","data",",","in","contrast","to","the",":","class",":","`","SubsetIndex","`","generator",",","which","partitions","data","into","randomly","into","equal","sizes",".","See","Also","--","--","--","--",":","class",":","`","FoldIndex","`",",",":","class",":","`","BlendIndex","`",",",":","class",":","`","SubsetIndex","`","References","--","--","--","--","--","..","[","#","]","Sapp",",","S.",",","van","der","Laan",",","M.","J.",",","&","Canny",",","J",".","(","2014",")",".","Subsemble",":","an","ensemble","method","for","combining","subset-specific","algorithm","fits",".","Journal","of","Applied","Statistics",",","41","(","6",")",",","1247-1259.","http",":","\/\/doi.org\/10.1080\/02664763.2013.864263","Parameters","--","--","--","--","--","partition_estimator",":","instance","Estimator","to","use","for","clustering",".","partitions",":","int","Number","of","partitions","the","estimator","will","create",".","folds",":","int","(","default","=","2",")","Number","of","folds","to","create","in","each","partition",".","``","folds","``","can","not","be","1","if","``","n_partition",">","1","``",".","Note","that","if","``","folds","=","1","``",",","both","the","train","and","test","set","will","index","the","full","data",".","fit_estimator",":","bool","(","default","=","True",")","whether","to","fit","the","estimator","separately","before","generating","labels",".","attr",":","str","(","default","=","'predict","'",")","the","attribute","to","use","for","generating","cluster","membership","labels",".","X",":","array-like","of","shape","[","n_samples",",","]",",","optional","the","training","set","to","partition",".","The","training","label","array","is","also",",","accepted",",","as","only","the","first","dimension","is","used",".","If","``","X","``","is","not","passed","at","instantiation",",","the","``","fit","``","method","must","be","called","before","``","generate","``",",","or","``","X","``","must","be","passed","as","an","argument","of","``","generate","``",".","raise_on_exception",":","bool","(","default","=","True",")","whether","to","warn","on","suspicious","slices","or","raise","an","error",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","sklearn.cluster","import","KMeans",">",">",">","from","mlens.index","import","ClusteredSubsetIndex",">",">",">",">",">",">","km","=","KMeans","(","3",",","random_state=0",")",">",">",">","X","=","np.arange","(","12",")",".reshape","(","-1",",","1",")",";","np.random.shuffle","(","X",")",">",">",">","print","(","``","Data",":","{","}","''",".format","(","X.ravel","(",")",")",")",">",">",">",">",">",">","s","=","ClusteredSubsetIndex","(","km",")",">",">",">","s.fit","(","X",")",">",">",">",">",">",">","P","=","s.partition_estimator.predict","(","X",")",">",">",">","print","(","``","cluster","labels",":","{","}","''",".format","(","P",")",")",">",">",">",">",">",">","for","j",",","i","in","enumerate","(","s.partition","(","as_array=True",")",")",":","...","print","(","``","partition","(","{","}",")","index",":","{","}",",","cluster","labels",":","{","}","''",".format","(","i",",","j","+","1",",","P","[","i","]",")",")",">",">",">",">",">",">","for","i","in","s.generate","(","as_array=True",")",":","...","print","(","``","train","fold","index",":","{","}",",","cluster","labels",":","{","}","''",".format","(","i","[","0","]",",","P","[","i","[","0","]","]",")",")","Data",":","[","8","7","5","2","4","10","11","1","3","6","9","0","]","cluster","labels",":","[","0","2","2","1","2","0","0","1","1","2","0","1","]","partition","(","1",")","index",":","[","0","5","6","10","]",",","cluster","labels",":","[","0","0","0","0","]","partition","(","2",")","index",":","[","3","7","8","11","]",",","cluster","labels",":","[","1","1","1","1","]","partition","(","3",")","index",":","[","1","2","4","9","]",",","cluster","labels",":","[","2","2","2","2","]","train","fold","index",":","[","0","3","5","]",",","cluster","labels",":","[","0","0","0","]","train","fold","index",":","[","6","10","]",",","cluster","labels",":","[","0","0","]","train","fold","index",":","[","2","7","]",",","cluster","labels",":","[","1","1","]","train","fold","index",":","[","9","11","]",",","cluster","labels",":","[","1","1","]","train","fold","index",":","[","1","4","]",",","cluster","labels",":","[","2","2","]","train","fold","index",":","[","8","]",",","cluster","labels",":","[","2","]"]
docstr: Method for storing array data.
  
  Parameters
  ----------
  X : array-like of shape [n_samples, n_features]
      input array.
  
  y : array-like of shape [n_samples, ]
      labels.
  
  job : str, ['fit', 'predict'] (default='fit')
      type of estimation job. If 'fit', the indexer will be fitted,
      which involves fitting the estimator. Otherwise, the indexer will
      not be fitted (since it is not used for prediction).
  
  Returns
  -------
  instance :
      indexer with stores sample size data.
docstr_tok: ["Method","for","storing","array","data",".","Parameters","--","--","--","--","--","X",":","array-like","of","shape","[","n_samples",",","n_features","]","input","array",".","y",":","array-like","of","shape","[","n_samples",",","]","labels",".","job",":","str",",","[","'fit","'",",","'predict","'","]","(","default='fit","'",")","type","of","estimation","job",".","If","'fit","'",",","the","indexer","will","be","fitted",",","which","involves","fitting","the","estimator",".","Otherwise",",","the","indexer","will","not","be","fitted","(","since","it","is","not","used","for","prediction",")",".","Returns","--","--","--","-","instance",":","indexer","with","stores","sample","size","data","."]
code: def fit(self, X, y=None, job="fit"):
      """Method for storing array data.
  
      Parameters
      ----------
      X : array-like of shape [n_samples, n_features]
          input array.
  
      y : array-like of shape [n_samples, ]
          labels.
  
      job : str, ['fit', 'predict'] (default='fit')
          type of estimation job. If 'fit', the indexer will be fitted,
          which involves fitting the estimator. Otherwise, the indexer will
          not be fitted (since it is not used for prediction).
  
      Returns
      -------
      instance :
          indexer with stores sample size data.
      """
      n = X.shape[0]
      self.n_samples = self.n_test_samples = n
  
      if "fit" in job:
          # Only generate new clusters if fitting an ensemble
          if self.fit_estimator:
              try:
                  self.partition_estimator.fit(X, y)
              except TypeError:
                  # Safeguard against estimators that do not accept y.
                  self.partition_estimator.fit(X)
  
          # Indexers are assumed to need fitting once, so we need to
          # generate cluster predictions during the fit call. To minimize
          # memory consumption, store cluster indexes as list of tuples
          self._clusters_ = self._get_partitions(X, y)
      self.__fitted__ = True
      return self
  
file_path: mlens/mlens/index/subsemble.py
imports: from __future__ import division
  import numpy
  from ._checks import check_subsample_index
  from .base import BaseIndex, partition, make_tuple, prune_train
label_desc: Use image node_id 2 for calling the ClusteredSubsetIndex obj's underlying member method code with example usage: obj.fit(X, y, job) and returns: self