class_docstr: 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.
  
  See Also
  --------
  :class:`FoldIndex`, :class:`BlendIndex`, :class:`Subsemble`
  
  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
  ----------
  partitions : int, list (default = 2)
      Number of partitions to split data in. If ``partitions=1``,
      :class:`SubsetIndex` reduces to standard K-Fold.
  
  folds : int (default = 2)
      Number of splits 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.
  
  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 mlens.index import SubsetIndex
  >>> X = np.arange(10)
  >>> idx = SubsetIndex(3, X=X)
  >>>
  >>> print('Expected partitions of X:')
  >>> print('J = 1: {!r}'.format(X[0:4]))
  >>> print('J = 2: {!r}'.format(X[4:7]))
  >>> print('J = 3: {!r}'.format(X[7:10]))
  >>> print('SubsetIndexer partitions:')
  >>> for i, part in enumerate(idx.partition(as_array=True)):
  ...     print('J = {}: {!r}'.format(i + 1, part))
  >>> print('SubsetIndexer folds on partitions:')
  >>> for i, (tri, tei) in enumerate(idx.generate()):
  ...     fold = i % 2 + 1
  ...     part = i // 2 + 1
  ...     train = np.hstack([np.arange(t0, t1) for t0, t1 in tri])
  ...     test = np.hstack([np.arange(t0, t1) for t0, t1 in tei])
  >>>     print("J = %i | f = %i | "
  ...           "train: %15r | test: %r" % (part, fold, train, test))
  Expected partitions of X:
  J = 1: array([0, 1, 2, 3])
  J = 2: array([4, 5, 6])
  J = 3: array([7, 8, 9])
  SubsetIndexer partitions:
  J = 1: array([0, 1, 2, 3])
  J = 2: array([4, 5, 6])
  J = 3: array([7, 8, 9])
  SubsetIndexer folds on partitions:
  J = 1 | f = 1 | train:   array([2, 3]) | test: array([0, 1, 4, 5, 7, 8])
  J = 1 | f = 2 | train:   array([0, 1]) | test: array([2, 3, 6, 9])
  J = 2 | f = 1 | train:      array([6]) | test: array([0, 1, 4, 5, 7, 8])
  J = 2 | f = 2 | train:   array([4, 5]) | test: array([2, 3, 6, 9])
  J = 3 | f = 1 | train:      array([9]) | test: array([0, 1, 4, 5, 7, 8])
  J = 3 | f = 2 | train:   array([7, 8]) | test: array([2, 3, 6, 9])
class_docstr_tok: ["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",".","See","Also","--","--","--","--",":","class",":","`","FoldIndex","`",",",":","class",":","`","BlendIndex","`",",",":","class",":","`","Subsemble","`","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","--","--","--","--","--","partitions",":","int",",","list","(","default","=","2",")","Number","of","partitions","to","split","data","in",".","If","``","partitions=1","``",",",":","class",":","`","SubsetIndex","`","reduces","to","standard","K-Fold",".","folds",":","int","(","default","=","2",")","Number","of","splits","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",".","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","mlens.index","import","SubsetIndex",">",">",">","X","=","np.arange","(","10",")",">",">",">","idx","=","SubsetIndex","(","3",",","X=X",")",">",">",">",">",">",">","print","(","'Expected","partitions","of","X",":","'",")",">",">",">","print","(","'","J","=","1",":","{","!","r","}","'.format","(","X","[","0:4","]",")",")",">",">",">","print","(","'","J","=","2",":","{","!","r","}","'.format","(","X","[","4:7","]",")",")",">",">",">","print","(","'","J","=","3",":","{","!","r","}","'.format","(","X","[","7:10","]",")",")",">",">",">","print","(","'SubsetIndexer","partitions",":","'",")",">",">",">","for","i",",","part","in","enumerate","(","idx.partition","(","as_array=True",")",")",":","...","print","(","'","J","=","{","}",":","{","!","r","}","'.format","(","i","+","1",",","part",")",")",">",">",">","print","(","'SubsetIndexer","folds","on","partitions",":","'",")",">",">",">","for","i",",","(","tri",",","tei",")","in","enumerate","(","idx.generate","(",")",")",":","...","fold","=","i","%","2","+","1","...","part","=","i","\/\/","2","+","1","...","train","=","np.hstack","(","[","np.arange","(","t0",",","t1",")","for","t0",",","t1","in","tri","]",")","...","test","=","np.hstack","(","[","np.arange","(","t0",",","t1",")","for","t0",",","t1","in","tei","]",")",">",">",">","print","(","``","J","=","%","i","|","f","=","%","i","|","``","...","``","train",":","%","15r","|","test",":","%","r","''","%","(","part",",","fold",",","train",",","test",")",")","Expected","partitions","of","X",":","J","=","1",":","array","(","[","0",",","1",",","2",",","3","]",")","J","=","2",":","array","(","[","4",",","5",",","6","]",")","J","=","3",":","array","(","[","7",",","8",",","9","]",")","SubsetIndexer","partitions",":","J","=","1",":","array","(","[","0",",","1",",","2",",","3","]",")","J","=","2",":","array","(","[","4",",","5",",","6","]",")","J","=","3",":","array","(","[","7",",","8",",","9","]",")","SubsetIndexer","folds","on","partitions",":","J","=","1","|","f","=","1","|","train",":","array","(","[","2",",","3","]",")","|","test",":","array","(","[","0",",","1",",","4",",","5",",","7",",","8","]",")","J","=","1","|","f","=","2","|","train",":","array","(","[","0",",","1","]",")","|","test",":","array","(","[","2",",","3",",","6",",","9","]",")","J","=","2","|","f","=","1","|","train",":","array","(","[","6","]",")","|","test",":","array","(","[","0",",","1",",","4",",","5",",","7",",","8","]",")","J","=","2","|","f","=","2","|","train",":","array","(","[","4",",","5","]",")","|","test",":","array","(","[","2",",","3",",","6",",","9","]",")","J","=","3","|","f","=","1","|","train",":","array","(","[","9","]",")","|","test",":","array","(","[","0",",","1",",","4",",","5",",","7",",","8","]",")","J","=","3","|","f","=","2","|","train",":","array","(","[","7",",","8","]",")","|","test",":","array","(","[","2",",","3",",","6",",","9","]",")"]
docstr: Get partition indices for training full subset estimators.
  
  Returns the index range for each partition of X.
  
  Parameters
  ----------
  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``.
  
  as_array : bool (default = False)
      whether to return partition as an index array. Otherwise tuples
      of ``(start, stop)`` indices are returned.
docstr_tok: ["Get","partition","indices","for","training","full","subset","estimators",".","Returns","the","index","range","for","each","partition","of","X.","Parameters","--","--","--","--","--","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","``",".","as_array",":","bool","(","default","=","False",")","whether","to","return","partition","as","an","index","array",".","Otherwise","tuples","of","``","(","start",",","stop",")","``","indices","are","returned","."]
code: def partition(self, X=None, as_array=False):
      """Get partition indices for training full subset estimators.
  
      Returns the index range for each partition of X.
  
      Parameters
      ----------
      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``.
  
      as_array : bool (default = False)
          whether to return partition as an index array. Otherwise tuples
          of ``(start, stop)`` indices are returned.
      """
      if not self.__fitted__:
          if X is None:
              raise AttributeError(
                  "No array provided to indexer. Either "
                  "pass an array to the 'generate' method, "
                  "or call the 'fit' method first or "
                  "initiate the instance with an array X "
                  "as argument."
              )
          else:
              # Need to call fit to continue
              self.fit(X)
  
      # Return the partition indices.
      parts = partition(self.n_samples, self.partitions)
      last = 0
      for size in parts:
          idx = last, last + size
  
          if as_array:
              idx = self._build_range(idx)
  
          yield idx
  
          last += size
  
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 3 for calling the SubsetIndex obj's underlying member method code with example usage: obj.partition(X, as_array) without return types