Skip to main content
QUICK REVIEW

[Paper Review] metric-learn: Metric Learning Algorithms in Python

William de Vazelhes, CJ Carey|arXiv (Cornell University)|Aug 13, 2019
Machine Learning and AlgorithmsComputer Science17 references31 citations
TL;DR

metric-learn is a Python package that implements supervised and weakly-supervised metric learning algorithms using a unified scikit-learn-compatible API, enabling seamless integration into machine learning pipelines for tasks like classification, clustering, and retrieval. It supports Mahalanobis distance learning via algorithms such as LMNN, MMC, and triplet/quadruplet learners, with full compatibility for cross-validation, hyperparameter tuning, and pipelining.

ABSTRACT

metric-learn is an open source Python package implementing supervised and weakly-supervised distance metric learning algorithms. As part of scikit-learn-contrib, it provides a unified interface compatible with scikit-learn which allows to easily perform cross-validation, model selection, and pipelining with other machine learning estimators. metric-learn is thoroughly tested and available on PyPi under the MIT licence.

Motivation & Objective

  • To provide a unified, production-ready Python package for metric learning algorithms that integrate smoothly with the scikit-learn ecosystem.
  • To support multiple supervision types—class labels, pairs, triplets, and quadruplets—within a single consistent interface.
  • To enable end-to-end machine learning workflows, including cross-validation, model selection, and pipelining with estimators like k-NN and LDA.
  • To offer a scalable, well-documented, and actively maintained open-source solution under the MIT license.
  • To bridge the gap between metric learning research and practical deployment by supporting both standard and emerging metric learning methods.

Proposed method

  • The package implements Mahalanobis distance learning by learning a linear transformation matrix L, where the distance between points x and x′ is defined as D_L(x,x′) = ||Lx - Lx′||₂.
  • All metric learners inherit from scikit-learn’s base classes (e.g., TransformerMixin), enabling compatibility with pipelines, cross-validation, and model selection.
  • Supervised learners use class labels to optimize a metric that pulls same-class points together and pushes different-class points apart.
  • Pair learners use binary labels (+1 for similar, -1 for dissimilar) on pairs of points to learn a metric that minimizes intra-pair distances for similar pairs.
  • Triplet and quadruplet learners use 3- and 4-tuples of points, respectively, to enforce that the first point is closer to the second than to the third (or the two first closer than the two last).
  • The package includes a threshold calibration method (calibrate_threshold) to automatically set distance thresholds for weakly-supervised prediction tasks.

Experimental results

Research questions

  • RQ1How can metric learning algorithms be unified under a single, scikit-learn-compatible interface to improve usability and integration in ML workflows?
  • RQ2What is the performance impact of using weakly-supervised metric learning (e.g., pair, triplet, quadruplet supervision) compared to fully supervised methods in real-world applications?
  • RQ3Can a single, extensible Python package efficiently support diverse metric learning algorithms across different supervision levels and data scales?
  • RQ4How does the integration of metric learning with scikit-learn pipelines affect model accuracy and development efficiency in downstream tasks like k-NN classification?
  • RQ5What are the key design principles for building a production-ready, open-source metric learning library that supports both classical and emerging algorithms?

Key findings

  • metric-learn supports 14 metric learning algorithms across four supervision types—supervised, pair, triplet, and quadruplet—through a consistent, scikit-learn-compatible API.
  • The package enables full integration with scikit-learn tools, including cross-validation, grid search, and pipeline composition, as demonstrated with a LMNN-kNN pipeline on the Wine dataset.
  • Weakly-supervised learners such as MMC achieve a mean ROC-AUC score of 0.893 ± 0.025 in cross-validation on the LFW pairs dataset, demonstrating strong performance with minimal supervision.
  • The package is available on PyPI and conda-forge, with full test coverage and active development, supporting Python 3.6 and later.
  • The implementation of components_ and get_mahalanobis_matrix allows users to extract and interpret the learned transformation and Mahalanobis matrices for analysis and visualization.
  • Future extensions include stochastic solvers for large-scale data and support for multi-label, high-dimensional, and nonlinear metric learning algorithms.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.