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: Get clustered partition indices from estimator.
  
  Returns the index range for each partition of X. See :func:`partition`
  for further details.
docstr_tok: ["Get","clustered","partition","indices","from","estimator",".","Returns","the","index","range","for","each","partition","of","X",".","See",":","func",":","`","partition","`","for","further","details","."]
code: def _get_partitions(self, X, y=None):
      """Get clustered partition indices from estimator.
  
      Returns the index range for each partition of X. See :func:`partition`
      for further details.
      """
      n_samples = X.shape[0]
  
      f = getattr(self.partition_estimator, self.attr)
      if self.partition_on == "X":
          cluster_ids = f(X)
      elif self.partition_on == "y":
          cluster_ids = f(y)
      else:
          cluster_ids = f(X, y)
  
      clusters = np.unique(cluster_ids)
      self.partitions = len(clusters)
  
      # Condense the cluster index array into a list of tuples
      out = list()  # list of cluster indexes
  
      index = np.arange(n_samples)
      for c in clusters:
          cluster_index = index[cluster_ids == c]
          cluster_index_tup = make_tuple(cluster_index)
          out.append(cluster_index_tup)
      return out
  
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 5 for calling the ClusteredSubsetIndex obj's underlying member method code with example usage: obj._get_partitions(X, y) and returns: out