class_docstr: Mahalanobis Metric for Clustering (MMC)
  
  MMC minimizes the sum of squared distances between similar points, while
  enforcing the sum of distances between dissimilar ones to be greater than
  one. This leads to a convex and, thus, local-minima-free optimization
  problem that can be solved efficiently.
  However, the algorithm involves the computation of eigenvalues, which is the
  main speed-bottleneck. Since it has initially been designed for clustering
  applications, one of the implicit assumptions of MMC is that all classes form
  a compact set, i.e., follow a unimodal distribution, which restricts the
  possible use-cases of this method. However, it is one of the earliest and a
  still often cited technique.
  
  Read more in the :ref:`User Guide <mmc>`.
  
  Parameters
  ----------
  max_iter : int, optional (default=100)
    Maximum number of iterations of the optimization procedure.
  
  max_proj : int, optional (default=10000)
    Maximum number of projection steps.
  
  tol : float, optional (default=1e-3)
    Convergence threshold for the optimization procedure.
  
  init : string or numpy array, optional (default='identity')
    Initialization of the Mahalanobis matrix. Possible options are
    'identity', 'covariance', 'random', and a numpy array of
    shape (n_features, n_features).
  
    'identity'
      An identity matrix of shape (n_features, n_features).
  
    'covariance'
      The (pseudo-)inverse of the covariance matrix.
  
    'random'
      The initial Mahalanobis matrix will be a random SPD matrix of
      shape
      `(n_features, n_features)`, generated using
      `sklearn.datasets.make_spd_matrix`.
  
    numpy array
      An SPD matrix of shape (n_features, n_features), that will
      be used as such to initialize the metric.
  
  diagonal : bool, optional (default=False)
    If True, a diagonal metric will be learned,
    i.e., a simple scaling of dimensions. The initialization will then
    be the diagonal coefficients of the matrix given as 'init'.
  
  diagonal_c : float, optional (default=1.0)
    Weight of the dissimilarity constraint for diagonal
    metric learning. Ignored if ``diagonal=False``.
  
  verbose : bool, optional (default=False)
    If True, prints information while learning
  
  preprocessor : array-like, shape=(n_samples, n_features) or callable
    The preprocessor to call to get tuples from indices. If array-like,
    tuples will be gotten like this: X[indices].
  
  random_state : int or numpy.RandomState or None, optional (default=None)
    A pseudo random number generator object or a seed for it if int. If
    ``init='random'``, ``random_state`` is used to initialize the random
    transformation.
  
  convergence_threshold : Renamed to tol. Will be deprecated in 0.7.0
  
  Attributes
  ----------
  n_iter_ : `int`
    The number of iterations the solver has run.
  
  components_ : `numpy.ndarray`, shape=(n_features, n_features)
    The linear transformation ``L`` deduced from the learned Mahalanobis
    metric (See function `components_from_metric`.)
  
  threshold_ : `float`
    If the distance metric between two points is lower than this threshold,
    points will be classified as similar, otherwise they will be
    classified as dissimilar.
  
  Examples
  --------
  >>> from metric_learn import MMC
  >>> pairs = [[[1.2, 7.5], [1.3, 1.5]],
  >>>          [[6.4, 2.6], [6.2, 9.7]],
  >>>          [[1.3, 4.5], [3.2, 4.6]],
  >>>          [[6.2, 5.5], [5.4, 5.4]]]
  >>> y = [1, 1, -1, -1]
  >>> # in this task we want points where the first feature is close to be
  >>> # closer to each other, no matter how close the second feature is
  >>> mmc = MMC()
  >>> mmc.fit(pairs, y)
  
  References
  ----------
  .. [1] Xing, Jordan, Russell, Ng. `Distance metric learning with application
         to clustering with side-information
         <http://papers.nips.cc/paper/2164-distance-metric-         learning-with-application-to-clustering-with-side-information.pdf>`_.
         NIPS 2002.
  
  See Also
  --------
  metric_learn.MMC : The original weakly-supervised algorithm
  :ref:`supervised_version` : The section of the project documentation
    that describes the supervised version of weakly supervised estimators.
class_docstr_tok: ["Mahalanobis","Metric","for","Clustering","(","MMC",")","MMC","minimizes","the","sum","of","squared","distances","between","similar","points",",","while","enforcing","the","sum","of","distances","between","dissimilar","ones","to","be","greater","than","one",".","This","leads","to","a","convex","and",",","thus",",","local-minima-free","optimization","problem","that","can","be","solved","efficiently",".","However",",","the","algorithm","involves","the","computation","of","eigenvalues",",","which","is","the","main","speed-bottleneck",".","Since","it","has","initially","been","designed","for","clustering","applications",",","one","of","the","implicit","assumptions","of","MMC","is","that","all","classes","form","a","compact","set",",","i.e.",",","follow","a","unimodal","distribution",",","which","restricts","the","possible","use-cases","of","this","method",".","However",",","it","is","one","of","the","earliest","and","a","still","often","cited","technique",".","Read","more","in","the",":","ref",":","`","User","Guide","<","mmc",">","`",".","Parameters","--","--","--","--","--","max_iter",":","int",",","optional","(","default=100",")","Maximum","number","of","iterations","of","the","optimization","procedure",".","max_proj",":","int",",","optional","(","default=10000",")","Maximum","number","of","projection","steps",".","tol",":","float",",","optional","(","default=1e-3",")","Convergence","threshold","for","the","optimization","procedure",".","init",":","string","or","numpy","array",",","optional","(","default='identity","'",")","Initialization","of","the","Mahalanobis","matrix",".","Possible","options","are","'identity","'",",","'covariance","'",",","'random","'",",","and","a","numpy","array","of","shape","(","n_features",",","n_features",")",".","'identity'","An","identity","matrix","of","shape","(","n_features",",","n_features",")",".","'covariance'","The","(","pseudo-",")","inverse","of","the","covariance","matrix",".","'random'","The","initial","Mahalanobis","matrix","will","be","a","random","SPD","matrix","of","shape","`","(","n_features",",","n_features",")","`",",","generated","using","`","sklearn.datasets.make_spd_matrix","`",".","numpy","array","An","SPD","matrix","of","shape","(","n_features",",","n_features",")",",","that","will","be","used","as","such","to","initialize","the","metric",".","diagonal",":","bool",",","optional","(","default=False",")","If","True",",","a","diagonal","metric","will","be","learned",",","i.e.",",","a","simple","scaling","of","dimensions",".","The","initialization","will","then","be","the","diagonal","coefficients","of","the","matrix","given","as","'init","'",".","diagonal_c",":","float",",","optional","(","default=1.0",")","Weight","of","the","dissimilarity","constraint","for","diagonal","metric","learning",".","Ignored","if","``","diagonal=False","``",".","verbose",":","bool",",","optional","(","default=False",")","If","True",",","prints","information","while","learning","preprocessor",":","array-like",",","shape=","(","n_samples",",","n_features",")","or","callable","The","preprocessor","to","call","to","get","tuples","from","indices",".","If","array-like",",","tuples","will","be","gotten","like","this",":","X","[","indices","]",".","random_state",":","int","or","numpy.RandomState","or","None",",","optional","(","default=None",")","A","pseudo","random","number","generator","object","or","a","seed","for","it","if","int",".","If","``","init='random","'","``",",","``","random_state","``","is","used","to","initialize","the","random","transformation",".","convergence_threshold",":","Renamed","to","tol",".","Will","be","deprecated","in","0.7.0","Attributes","--","--","--","--","--","n_iter_",":","`","int","`","The","number","of","iterations","the","solver","has","run",".","components_",":","`","numpy.ndarray","`",",","shape=","(","n_features",",","n_features",")","The","linear","transformation","``","L","``","deduced","from","the","learned","Mahalanobis","metric","(","See","function","`","components_from_metric","`",".",")","threshold_",":","`","float","`","If","the","distance","metric","between","two","points","is","lower","than","this","threshold",",","points","will","be","classified","as","similar",",","otherwise","they","will","be","classified","as","dissimilar",".","Examples","--","--","--","--",">",">",">","from","metric_learn","import","MMC",">",">",">","pairs","=","[","[","[","1.2",",","7.5","]",",","[","1.3",",","1.5","]","]",",",">",">",">","[","[","6.4",",","2.6","]",",","[","6.2",",","9.7","]","]",",",">",">",">","[","[","1.3",",","4.5","]",",","[","3.2",",","4.6","]","]",",",">",">",">","[","[","6.2",",","5.5","]",",","[","5.4",",","5.4","]","]","]",">",">",">","y","=","[","1",",","1",",","-1",",","-1","]",">",">",">","#","in","this","task","we","want","points","where","the","first","feature","is","close","to","be",">",">",">","#","closer","to","each","other",",","no","matter","how","close","the","second","feature","is",">",">",">","mmc","=","MMC","(",")",">",">",">","mmc.fit","(","pairs",",","y",")","References","--","--","--","--","--","..","[","1","]","Xing",",","Jordan",",","Russell",",","Ng",".","`","Distance","metric","learning","with","application","to","clustering","with","side-information","<","http",":","\/\/papers.nips.cc\/paper\/2164-distance-metric-","learning-with-application-to-clustering-with-side-information.pdf",">","`","_",".","NIPS","2002",".","See","Also","--","--","--","--","metric_learn.MMC",":","The","original","weakly-supervised","algorithm",":","ref",":","`","supervised_version","`",":","The","section","of","the","project","documentation","that","describes","the","supervised","version","of","weakly","supervised","estimators","."]
docstr: Learn the MMC model.
  
  The threshold will be calibrated on the trainset using the parameters
  `calibration_params`.
  
  Parameters
  ----------
  pairs : array-like, shape=(n_constraints, 2, n_features) or            (n_constraints, 2)
    3D Array of pairs with each row corresponding to two points,
    or 2D array of indices of pairs if the metric learner uses a
    preprocessor.
  
  y : array-like, of shape (n_constraints,)
    Labels of constraints. Should be -1 for dissimilar pair, 1 for similar.
  
  calibration_params : `dict` or `None`
    Dictionary of parameters to give to `calibrate_threshold` for the
    threshold calibration step done at the end of `fit`. If `None` is
    given, `calibrate_threshold` will use the default parameters.
  
  Returns
  -------
  self : object
    Returns the instance.
docstr_tok: ["Learn","the","MMC","model",".","The","threshold","will","be","calibrated","on","the","trainset","using","the","parameters","`","calibration_params","`",".","Parameters","--","--","--","--","--","pairs",":","array-like",",","shape=","(","n_constraints",",","2",",","n_features",")","or","(","n_constraints",",","2",")","3D","Array","of","pairs","with","each","row","corresponding","to","two","points",",","or","2D","array","of","indices","of","pairs","if","the","metric","learner","uses","a","preprocessor",".","y",":","array-like",",","of","shape","(","n_constraints",",",")","Labels","of","constraints",".","Should","be","-1","for","dissimilar","pair",",","1","for","similar",".","calibration_params",":","`","dict","`","or","`","None","`","Dictionary","of","parameters","to","give","to","`","calibrate_threshold","`","for","the","threshold","calibration","step","done","at","the","end","of","`","fit","`",".","If","`","None","`","is","given",",","`","calibrate_threshold","`","will","use","the","default","parameters",".","Returns","--","--","--","-","self",":","object","Returns","the","instance","."]
code: def fit(self, pairs, y, calibration_params=None):
      """Learn the MMC model.
  
      The threshold will be calibrated on the trainset using the parameters
      `calibration_params`.
  
      Parameters
      ----------
      pairs : array-like, shape=(n_constraints, 2, n_features) or \
             (n_constraints, 2)
        3D Array of pairs with each row corresponding to two points,
        or 2D array of indices of pairs if the metric learner uses a
        preprocessor.
  
      y : array-like, of shape (n_constraints,)
        Labels of constraints. Should be -1 for dissimilar pair, 1 for similar.
  
      calibration_params : `dict` or `None`
        Dictionary of parameters to give to `calibrate_threshold` for the
        threshold calibration step done at the end of `fit`. If `None` is
        given, `calibrate_threshold` will use the default parameters.
  
      Returns
      -------
      self : object
        Returns the instance.
      """
      calibration_params = (
          calibration_params
          if calibration_params is not None
          else dict()
      )
      self._validate_calibration_params(**calibration_params)
      self._fit(pairs, y)
      self.calibrate_threshold(pairs, y, **calibration_params)
      return self
  
imports: import numpy
  from sklearn.base import TransformerMixin
  from sklearn.utils.validation import assert_all_finite
  from .base_metric import _PairsClassifierMixin, MahalanobisMixin
  from .constraints import Constraints, wrap_pairs
  from ._util import components_from_metric, _initialize_metric_mahalanobis
  import warnings
label_desc: Use image node_id 1 for calling the MMC obj's underlying member method code with example usage: obj.fit(pairs, y, calibration_params) and returns: self