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 positive pairs and negative pairs from labeled data.
  
  Positive pairs are formed by randomly drawing ``n_constraints`` pairs of
  points with the same label. Negative pairs are formed by randomly drawing
  ``n_constraints`` pairs of points with different label.
  
  In the case where it is not possible to generate enough positive or
  negative pairs, a smaller number of pairs will be returned with a warning.
  
  Parameters
  ----------
  n_constraints : int
    Number of positive and negative constraints to generate.
  
  same_length : bool, optional (default=False)
    If True, forces the number of positive and negative pairs to be
    equal by ignoring some pairs from the larger set.
  
  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_constraints : Renamed to n_constraints. Will be deprecated in 0.7.0
  
  Returns
  -------
  a : array-like, shape=(n_constraints,)
    1D array of indicators for the left elements of positive pairs.
  
  b : array-like, shape=(n_constraints,)
    1D array of indicators for the right elements of positive pairs.
  
  c : array-like, shape=(n_constraints,)
    1D array of indicators for the left elements of negative pairs.
  
  d : array-like, shape=(n_constraints,)
    1D array of indicators for the right elements of negative pairs.
docstr_tok: ["Generates","positive","pairs","and","negative","pairs","from","labeled","data",".","Positive","pairs","are","formed","by","randomly","drawing","``","n_constraints","``","pairs","of","points","with","the","same","label",".","Negative","pairs","are","formed","by","randomly","drawing","``","n_constraints","``","pairs","of","points","with","different","label",".","In","the","case","where","it","is","not","possible","to","generate","enough","positive","or","negative","pairs",",","a","smaller","number","of","pairs","will","be","returned","with","a","warning",".","Parameters","--","--","--","--","--","n_constraints",":","int","Number","of","positive","and","negative","constraints","to","generate",".","same_length",":","bool",",","optional","(","default=False",")","If","True",",","forces","the","number","of","positive","and","negative","pairs","to","be","equal","by","ignoring","some","pairs","from","the","larger","set",".","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_constraints",":","Renamed","to","n_constraints",".","Will","be","deprecated","in","0.7.0","Returns","--","--","--","-","a",":","array-like",",","shape=","(","n_constraints",",",")","1D","array","of","indicators","for","the","left","elements","of","positive","pairs",".","b",":","array-like",",","shape=","(","n_constraints",",",")","1D","array","of","indicators","for","the","right","elements","of","positive","pairs",".","c",":","array-like",",","shape=","(","n_constraints",",",")","1D","array","of","indicators","for","the","left","elements","of","negative","pairs",".","d",":","array-like",",","shape=","(","n_constraints",",",")","1D","array","of","indicators","for","the","right","elements","of","negative","pairs","."]
code: def positive_negative_pairs(
      self,
      n_constraints,
      same_length=False,
      random_state=None,
      num_constraints="deprecated",
  ):
      """
      Generates positive pairs and negative pairs from labeled data.
  
      Positive pairs are formed by randomly drawing ``n_constraints`` pairs of
      points with the same label. Negative pairs are formed by randomly drawing
      ``n_constraints`` pairs of points with different label.
  
      In the case where it is not possible to generate enough positive or
      negative pairs, a smaller number of pairs will be returned with a warning.
  
      Parameters
      ----------
      n_constraints : int
        Number of positive and negative constraints to generate.
  
      same_length : bool, optional (default=False)
        If True, forces the number of positive and negative pairs to be
        equal by ignoring some pairs from the larger set.
  
      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_constraints : Renamed to n_constraints. Will be deprecated in 0.7.0
  
      Returns
      -------
      a : array-like, shape=(n_constraints,)
        1D array of indicators for the left elements of positive pairs.
  
      b : array-like, shape=(n_constraints,)
        1D array of indicators for the right elements of positive pairs.
  
      c : array-like, shape=(n_constraints,)
        1D array of indicators for the left elements of negative pairs.
  
      d : array-like, shape=(n_constraints,)
        1D array of indicators for the right elements of negative pairs.
      """
      if num_constraints != "deprecated":
          warnings.warn(
              '"num_constraints" parameter has been renamed to'
              ' "n_constraints". It has been deprecated in'
              " version 0.6.3 and will be removed in 0.7.0"
              "",
              FutureWarning,
          )
          self.n_constraints = num_constraints
      else:
          self.n_constraints = n_constraints
      random_state = check_random_state(random_state)
      a, b = self._pairs(
          n_constraints, same_label=True, random_state=random_state
      )
      c, d = self._pairs(
          n_constraints, same_label=False, random_state=random_state
      )
      if same_length and len(a) != len(c):
          n = min(len(a), len(c))
          return a[:n], b[:n], c[:n], d[:n]
      return a, b, c, d
  
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 2 for calling the Constraints obj's underlying member method code with example usage: obj.positive_negative_pairs(n_constraints, same_length, random_state, num_constraints) and returns: a,  b,  c,  d, a,  b,  c,  d