class_docstr: Class to build constraints from labeled data.
  
  See more in the :ref:`User Guide <supervised_version>`.
  
  Parameters
  ----------
  partial_labels : `numpy.ndarray` of ints, shape=(n_samples,)
    Array of labels, with -1 indicating unknown label.
  
  Attributes
  ----------
  partial_labels : `numpy.ndarray` of ints, shape=(n_samples,)
    Array of labels, with -1 indicating unknown label.
class_docstr_tok: ["Class","to","build","constraints","from","labeled","data",".","See","more","in","the",":","ref",":","`","User","Guide","<","supervised_version",">","`",".","Parameters","--","--","--","--","--","partial_labels",":","`","numpy.ndarray","`","of","ints",",","shape=","(","n_samples",",",")","Array","of","labels",",","with","-1","indicating","unknown","label",".","Attributes","--","--","--","--","--","partial_labels",":","`","numpy.ndarray","`","of","ints",",","shape=","(","n_samples",",",")","Array","of","labels",",","with","-1","indicating","unknown","label","."]
docstr: Generates chunks from labeled data.
  
  Each of ``n_chunks`` chunks is composed of ``chunk_size`` points from
  the same class drawn at random. Each point can belong to at most 1 chunk.
  
  In the case where there is not enough points to generate ``n_chunks``
  chunks of size ``chunk_size``, a ValueError will be raised.
  
  Parameters
  ----------
  n_chunks : int, optional (default=100)
    Number of chunks to generate.
  
  chunk_size : int, optional (default=2)
    Number of points in each chunk.
  
  random_state : int or numpy.RandomState or None, optional (default=None)
    A pseudo random number generator object or a seed for it if int.
  
  num_chunks : Renamed to n_chunks. Will be deprecated in 0.7.0
  
  Returns
  -------
  chunks : array-like, shape=(n_samples,)
    1D array of chunk indicators, where -1 indicates that the point does not
    belong to any chunk.
docstr_tok: ["Generates","chunks","from","labeled","data",".","Each","of","``","n_chunks","``","chunks","is","composed","of","``","chunk_size","``","points","from","the","same","class","drawn","at","random",".","Each","point","can","belong","to","at","most","1","chunk",".","In","the","case","where","there","is","not","enough","points","to","generate","``","n_chunks","``","chunks","of","size","``","chunk_size","``",",","a","ValueError","will","be","raised",".","Parameters","--","--","--","--","--","n_chunks",":","int",",","optional","(","default=100",")","Number","of","chunks","to","generate",".","chunk_size",":","int",",","optional","(","default=2",")","Number","of","points","in","each","chunk",".","random_state",":","int","or","numpy.RandomState","or","None",",","optional","(","default=None",")","A","pseudo","random","number","generator","object","or","a","seed","for","it","if","int",".","num_chunks",":","Renamed","to","n_chunks",".","Will","be","deprecated","in","0.7.0","Returns","--","--","--","-","chunks",":","array-like",",","shape=","(","n_samples",",",")","1D","array","of","chunk","indicators",",","where","-1","indicates","that","the","point","does","not","belong","to","any","chunk","."]
code: def chunks(
      self,
      n_chunks=100,
      chunk_size=2,
      random_state=None,
      num_chunks="deprecated",
  ):
      """
      Generates chunks from labeled data.
  
      Each of ``n_chunks`` chunks is composed of ``chunk_size`` points from
      the same class drawn at random. Each point can belong to at most 1 chunk.
  
      In the case where there is not enough points to generate ``n_chunks``
      chunks of size ``chunk_size``, a ValueError will be raised.
  
      Parameters
      ----------
      n_chunks : int, optional (default=100)
        Number of chunks to generate.
  
      chunk_size : int, optional (default=2)
        Number of points in each chunk.
  
      random_state : int or numpy.RandomState or None, optional (default=None)
        A pseudo random number generator object or a seed for it if int.
  
      num_chunks : Renamed to n_chunks. Will be deprecated in 0.7.0
  
      Returns
      -------
      chunks : array-like, shape=(n_samples,)
        1D array of chunk indicators, where -1 indicates that the point does not
        belong to any chunk.
      """
      if num_chunks != "deprecated":
          warnings.warn(
              '"num_chunks" parameter has been renamed to'
              ' "n_chunks". It has been deprecated in'
              " version 0.6.3 and will be removed in 0.7.0"
              "",
              FutureWarning,
          )
          n_chunks = num_chunks
      random_state = check_random_state(random_state)
      chunks = -np.ones_like(self.partial_labels, dtype=int)
      uniq, lookup = np.unique(self.partial_labels, return_inverse=True)
      unknown_uniq = np.where(uniq < 0)[0]
      all_inds = [
          set(np.where(lookup == c)[0])
          for c in range(len(uniq))
          if c not in unknown_uniq
      ]
      max_chunks = int(np.sum([len(s) // chunk_size for s in all_inds]))
      if max_chunks < n_chunks:
          raise ValueError(
              (
                  "Not enough possible chunks of %d elements in each"
                  " class to form expected %d chunks - maximum number"
                  " of chunks is %d"
              )
              % (chunk_size, n_chunks, max_chunks)
          )
      idx = 0
      while idx < n_chunks and all_inds:
          if len(all_inds) == 1:
              c = 0
          else:
              c = random_state.randint(0, high=len(all_inds) - 1)
          inds = all_inds[c]
          if len(inds) < chunk_size:
              del all_inds[c]
              continue
          ii = random_state.choice(
              list(inds), chunk_size, replace=False
          )
          inds.difference_update(ii)
          chunks[ii] = idx
          idx += 1
      return chunks
  
file_path: metric-learn/metric_learn/constraints.py
imports: import numpy
  import warnings
  from sklearn.utils import check_random_state
  from sklearn.neighbors import NearestNeighbors
label_desc: Use image node_id 5 for calling the Constraints obj's underlying member method code with example usage: obj.chunks(n_chunks, chunk_size, random_state, num_chunks) and returns: chunks