Metric Learning
Metric Learning (Distance Metric Learning) · Also known as: Distance Metric Learning, Similarity Learning, DML, Representation Learning via Distance
Metric learning is a machine-learning framework that trains a distance or similarity function from data so that semantically similar examples end up close together in the learned space while dissimilar examples are pushed apart. Unlike fixed distances such as Euclidean, the learned metric adapts to the structure of the task, making downstream classifiers, clusterers, and retrieval systems significantly more accurate.
Read the full method
Sign in with a free account to read this section.
Method map
The neighbourhood of related methods — select a node to explore.
+4 more
When to use it
Use metric learning when the downstream task is inherently similarity-based — e.g., few-shot classification, face verification, medical image retrieval, speaker identification, or product recommendation — and when a fixed Euclidean distance performs poorly because features have unequal relevance. It excels with moderate-to-large labeled datasets and high-dimensional inputs such as images or text embeddings. Avoid it when you have very few labeled examples per class (fewer than about 5–10 per class), when the final goal is a simple tabular regression or classification well served by logistic regression or gradient boosting, or when interpretability in terms of explicit feature coefficients is required.
Strengths & limitations
- Adapts the geometry of the feature space to the specific task, substantially boosting nearest-neighbor and clustering accuracy.
- Enables few-shot recognition: once a good metric is learned, classifying new classes requires only a handful of examples.
- Transfers well across domains — a metric learned on one dataset can be fine-tuned for a related task with little additional data.
- Model-agnostic: the learned embedding can feed any downstream algorithm (k-NN, SVM, k-means) without retraining those components.
- Contrastive and triplet formulations scale to very large datasets via mini-batch sampling.
- Triplet and contrastive losses require careful pair/triplet mining; random sampling yields mostly easy, uninformative pairs and slows training drastically.
- Linear Mahalanobis methods scale quadratically with feature dimensionality, becoming prohibitive in very high dimensions without dimensionality reduction.
- Requires labeled or pairwise-constraint data; fully unsupervised settings limit what can be learned without additional assumptions.
- Evaluation is indirect — metric quality must be assessed through a downstream task, not a single loss value.
Frequently asked
What is the difference between metric learning and contrastive learning?
Contrastive learning is a specific family of metric learning objectives (e.g., contrastive loss, SimCLR) that contrast positive and negative pairs. Metric learning is the broader framework that also includes Mahalanobis methods, triplet losses, and proxy-based objectives.
How many examples per class do I need?
Linear Mahalanobis methods can work with as few as 10–20 examples per class. Deep metric learning generally requires tens to hundreds of examples per class to learn useful embeddings, though pre-trained backbones can reduce this requirement substantially.
Is metric learning the same as dimensionality reduction?
Not exactly. Methods like PCA or UMAP reduce dimensions without direct supervision. Metric learning uses class or pairwise supervision to shape the geometry, so the resulting space is task-discriminative, not just compact.
Can metric learning handle imbalanced classes?
Yes, but pair/triplet sampling must be stratified to avoid the dominant class overwhelming the batch. Proxy-based losses (Proxy-NCA, Proxy-Anchor) are more robust to class imbalance than triplet sampling.
When should I use metric learning instead of a standard classifier?
Prefer metric learning when you need to generalize to classes unseen at training time (open-set recognition, few-shot learning), or when the task is retrieval rather than fixed-class prediction.
Sources
- Xing, E. P., Jordan, M. I., Russell, S., & Ng, A. Y. (2003). Distance metric learning with application to clustering with side-information. In Advances in Neural Information Processing Systems (NIPS), 16, 505–512. link ↗
- Weinberger, K. Q., & Saul, L. K. (2009). Distance metric learning for large margin nearest neighbor classification. Journal of Machine Learning Research, 10, 207–244. link ↗
How to cite this page
ScholarGate. (2026, June 3). Metric Learning (Distance Metric Learning). ScholarGate. https://scholargate.app/en/machine-learning/metric-learning
Which method?
Set this method beside its closest kin and read them side by side — the library lays the books on the table; the choice is yours.
- Few-shot LearningMachine learning↔ compare
- Gaussian ProcessMachine learning↔ compare
- Self-supervised LearningMachine learning↔ compare
- Semi-supervised LearningMachine learning↔ compare
- Transfer LearningMachine learning↔ compare