class_docstr: Large Margin Nearest Neighbor (LMNN)
  
  LMNN learns a Mahalanobis distance metric in the kNN classification
  setting. The learned metric attempts to keep close k-nearest neighbors
  from the same class, while keeping examples from different classes
  separated by a large margin. This algorithm makes no assumptions about
  the distribution of the data.
  
  Read more in the :ref:`User Guide <lmnn>`.
  
  Parameters
  ----------
  init : string or numpy array, optional (default='auto')
    Initialization of the linear transformation. Possible options are
    'auto', 'pca', 'identity', 'random', and a numpy array of shape
    (n_features_a, n_features_b).
  
    'auto'
      Depending on ``n_components``, the most reasonable initialization
      will be chosen. If ``n_components <= n_classes`` we use 'lda', as
      it uses labels information. If not, but
      ``n_components < min(n_features, n_samples)``, we use 'pca', as
      it projects data in meaningful directions (those of higher
      variance). Otherwise, we just use 'identity'.
  
    'pca'
      ``n_components`` principal components of the inputs passed
      to :meth:`fit` will be used to initialize the transformation.
      (See `sklearn.decomposition.PCA`)
  
    'lda'
      ``min(n_components, n_classes)`` most discriminative
      components of the inputs passed to :meth:`fit` will be used to
      initialize the transformation. (If ``n_components > n_classes``,
      the rest of the components will be zero.) (See
      `sklearn.discriminant_analysis.LinearDiscriminantAnalysis`)
  
    'identity'
      If ``n_components`` is strictly smaller than the
      dimensionality of the inputs passed to :meth:`fit`, the identity
      matrix will be truncated to the first ``n_components`` rows.
  
    'random'
      The initial transformation will be a random array of shape
      `(n_components, n_features)`. Each value is sampled from the
      standard normal distribution.
  
    numpy array
      n_features_b must match the dimensionality of the inputs passed to
      :meth:`fit` and n_features_a must be less than or equal to that.
      If ``n_components`` is not None, n_features_a must match it.
  
  n_neighbors : int, optional (default=3)
    Number of neighbors to consider, not including self-edges.
  
  min_iter : int, optional (default=50)
    Minimum number of iterations of the optimization procedure.
  
  max_iter : int, optional (default=1000)
    Maximum number of iterations of the optimization procedure.
  
  learn_rate : float, optional (default=1e-7)
    Learning rate of the optimization procedure
  
  tol : float, optional (default=0.001)
    Tolerance of the optimization procedure. If the objective value varies
    less than `tol`, we consider the algorithm has converged and stop it.
  
  verbose : bool, optional (default=False)
    Whether to print the progress of the optimization procedure.
  
  regularization: float, optional (default=0.5)
    Relative weight between pull and push terms, with 0.5 meaning equal
    weight.
  
  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 formed like this: X[indices].
  
  n_components : int or None, optional (default=None)
    Dimensionality of reduced space (if None, defaults to dimension of X).
  
  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. If ``init='pca'``, ``random_state`` is passed as an
    argument to PCA when initializing the transformation.
  
  k : Renamed to n_neighbors. Will be deprecated in 0.7.0
  
  Attributes
  ----------
  n_iter_ : `int`
    The number of iterations the solver has run.
  
  components_ : `numpy.ndarray`, shape=(n_components, n_features)
    The learned linear transformation ``L``.
  
  Examples
  --------
  
  >>> import numpy as np
  >>> from metric_learn import LMNN
  >>> from sklearn.datasets import load_iris
  >>> iris_data = load_iris()
  >>> X = iris_data['data']
  >>> Y = iris_data['target']
  >>> lmnn = LMNN(n_neighbors=5, learn_rate=1e-6)
  >>> lmnn.fit(X, Y, verbose=False)
  
  References
  ----------
  .. [1] K. Q. Weinberger, J. Blitzer, L. K. Saul. `Distance Metric
         Learning for Large Margin Nearest Neighbor Classification
         <http://papers.nips.cc/paper/2795-distance-metric         -learning-for-large-margin-nearest-neighbor-classification>`_. NIPS
         2005.
class_docstr_tok: ["Large","Margin","Nearest","Neighbor","(","LMNN",")","LMNN","learns","a","Mahalanobis","distance","metric","in","the","kNN","classification","setting",".","The","learned","metric","attempts","to","keep","close","k-nearest","neighbors","from","the","same","class",",","while","keeping","examples","from","different","classes","separated","by","a","large","margin",".","This","algorithm","makes","no","assumptions","about","the","distribution","of","the","data",".","Read","more","in","the",":","ref",":","`","User","Guide","<","lmnn",">","`",".","Parameters","--","--","--","--","--","init",":","string","or","numpy","array",",","optional","(","default='auto","'",")","Initialization","of","the","linear","transformation",".","Possible","options","are","'auto","'",",","'pca","'",",","'identity","'",",","'random","'",",","and","a","numpy","array","of","shape","(","n_features_a",",","n_features_b",")",".","'auto'","Depending","on","``","n_components","``",",","the","most","reasonable","initialization","will","be","chosen",".","If","``","n_components","<","=","n_classes","``","we","use","'lda","'",",","as","it","uses","labels","information",".","If","not",",","but","``","n_components","<","min","(","n_features",",","n_samples",")","``",",","we","use","'pca","'",",","as","it","projects","data","in","meaningful","directions","(","those","of","higher","variance",")",".","Otherwise",",","we","just","use","'identity","'",".","'pca'","``","n_components","``","principal","components","of","the","inputs","passed","to",":","meth",":","`","fit","`","will","be","used","to","initialize","the","transformation",".","(","See","`","sklearn.decomposition.PCA","`",")","'lda'","``","min","(","n_components",",","n_classes",")","``","most","discriminative","components","of","the","inputs","passed","to",":","meth",":","`","fit","`","will","be","used","to","initialize","the","transformation",".","(","If","``","n_components",">","n_classes","``",",","the","rest","of","the","components","will","be","zero",".",")","(","See","`","sklearn.discriminant_analysis.LinearDiscriminantAnalysis","`",")","'identity'","If","``","n_components","``","is","strictly","smaller","than","the","dimensionality","of","the","inputs","passed","to",":","meth",":","`","fit","`",",","the","identity","matrix","will","be","truncated","to","the","first","``","n_components","``","rows",".","'random'","The","initial","transformation","will","be","a","random","array","of","shape","`","(","n_components",",","n_features",")","`",".","Each","value","is","sampled","from","the","standard","normal","distribution",".","numpy","array","n_features_b","must","match","the","dimensionality","of","the","inputs","passed","to",":","meth",":","`","fit","`","and","n_features_a","must","be","less","than","or","equal","to","that",".","If","``","n_components","``","is","not","None",",","n_features_a","must","match","it",".","n_neighbors",":","int",",","optional","(","default=3",")","Number","of","neighbors","to","consider",",","not","including","self-edges",".","min_iter",":","int",",","optional","(","default=50",")","Minimum","number","of","iterations","of","the","optimization","procedure",".","max_iter",":","int",",","optional","(","default=1000",")","Maximum","number","of","iterations","of","the","optimization","procedure",".","learn_rate",":","float",",","optional","(","default=1e-7",")","Learning","rate","of","the","optimization","procedure","tol",":","float",",","optional","(","default=0.001",")","Tolerance","of","the","optimization","procedure",".","If","the","objective","value","varies","less","than","`","tol","`",",","we","consider","the","algorithm","has","converged","and","stop","it",".","verbose",":","bool",",","optional","(","default=False",")","Whether","to","print","the","progress","of","the","optimization","procedure",".","regularization",":","float",",","optional","(","default=0.5",")","Relative","weight","between","pull","and","push","terms",",","with","0.5","meaning","equal","weight",".","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","formed","like","this",":","X","[","indices","]",".","n_components",":","int","or","None",",","optional","(","default=None",")","Dimensionality","of","reduced","space","(","if","None",",","defaults","to","dimension","of","X",")",".","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",".","If","``","init='pca","'","``",",","``","random_state","``","is","passed","as","an","argument","to","PCA","when","initializing","the","transformation",".","k",":","Renamed","to","n_neighbors",".","Will","be","deprecated","in","0.7.0","Attributes","--","--","--","--","--","n_iter_",":","`","int","`","The","number","of","iterations","the","solver","has","run",".","components_",":","`","numpy.ndarray","`",",","shape=","(","n_components",",","n_features",")","The","learned","linear","transformation","``","L","``",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","metric_learn","import","LMNN",">",">",">","from","sklearn.datasets","import","load_iris",">",">",">","iris_data","=","load_iris","(",")",">",">",">","X","=","iris_data","[","'data","'","]",">",">",">","Y","=","iris_data","[","'target","'","]",">",">",">","lmnn","=","LMNN","(","n_neighbors=5",",","learn_rate=1e-6",")",">",">",">","lmnn.fit","(","X",",","Y",",","verbose=False",")","References","--","--","--","--","--","..","[","1","]","K.","Q.","Weinberger",",","J.","Blitzer",",","L.","K.","Saul",".","`","Distance","Metric","Learning","for","Large","Margin","Nearest","Neighbor","Classification","<","http",":","\/\/papers.nips.cc\/paper\/2795-distance-metric","-learning-for-large-margin-nearest-neighbor-classification",">","`","_",".","NIPS","2005","."]
code: def _find_impostors(self, furthest_neighbors, X, label_inds, L):
      Lx = X.dot(L.T)
      margin_radii = 1 + _inplace_paired_L2(Lx[furthest_neighbors], Lx)
      impostors = []
      for label in self.labels_[:-1]:
          (in_inds,) = np.nonzero(label_inds == label)
          (out_inds,) = np.nonzero(label_inds > label)
          dist = euclidean_distances(
              Lx[out_inds], Lx[in_inds], squared=True
          )
          i1, j1 = np.nonzero(dist < margin_radii[out_inds][:, None])
          i2, j2 = np.nonzero(dist < margin_radii[in_inds])
          i = np.hstack((i1, i2))
          j = np.hstack((j1, j2))
          if i.size > 0:
              # get unique (i,j) pairs using index trickery
              shape = (i.max() + 1, j.max() + 1)
              tmp = np.ravel_multi_index((i, j), shape)
              i, j = np.unravel_index(np.unique(tmp), shape)
          impostors.append(np.vstack((in_inds[j], out_inds[i])))
      if len(impostors) == 0:
          # No impostors detected
          return impostors
      return np.hstack(impostors)
  
file_path: metric-learn/metric_learn/lmnn.py
imports: import numpy
  from collections import Counter
  from sklearn.metrics import euclidean_distances
  from sklearn.base import TransformerMixin
  import warnings
  from ._util import _initialize_components, _check_n_components
  from .base_metric import MahalanobisMixin
label_desc: Use image node_id 5 for calling the LMNN obj's underlying member method code with example usage: obj._find_impostors(furthest_neighbors, X, label_inds, L) and returns: np, impostors