- Introduced by
- Multiple contributors (Weinberger, Saul, et al.)
- Year
- 2000s–2010s
- Type
- Ensemble of learned distance metrics
- Family
- Machine learning
What does it do?
Ensemble Metric Learning trains several distance metric learners, each on a different data view, feature subspace, or objective, and combines their metrics into one similarity function.
The aim is to reduce the variance of any single learned metric, which can matter for nearest-neighbor classification, retrieval, and few-shot learning. The benefit depends on the base learners being genuinely different from one another.
The intuition behind the method
A single learned distance metric reflects the choices made in its training: the features it sees, the constraints it is given, and its optimisation. Such a metric can be systematically wrong in some regions of the data space. Training several metric learners with different perspectives, then combining their distances, may average out some of these errors. Where the base metrics disagree strongly, the combined similarity is less settled, which can be worth inspecting. The combination does not guarantee better accuracy; it helps only when the individual errors are not highly correlated.
History
Ensemble metric learning is best understood as a construction built on single-metric distance learning rather than as a method with one named originator. Xing et al. (2002) learned a distance metric from side-information, and Large Margin Nearest Neighbor (LMNN; Weinberger & Saul, 2009) learned a Mahalanobis metric for nearest-neighbor classification. Parametric local metric learning for nearest-neighbor classification (Wang et al., 2012) is a further example of learned metrics for the same task. Combining several such learned metrics into one distance is a general construction.
When to use it
Ensemble Metric Learning is worth considering when the features are heterogeneous and hard to weight by hand, when a single metric learner gives unstable results across cross-validation folds, or when the downstream task depends heavily on the distance function, as in retrieval or nearest-neighbor classification. It may also help in few-shot settings where labeled data is scarce and variance reduction matters. Avoid it when the distance function must be interpretable, when computing budget is tight, or when the dataset is small enough that training several learners overfits each split.
Limitations and considerations
- Training K metric learners multiplies the training cost by K, which can be a serious constraint for deep embedding models on large datasets.
- Choosing how to combine the metrics, uniform or learned weights, adds a further choice that must be validated.
- Diversity must be designed in; an ensemble of near-identical learners gives little benefit over one learner.
- The combined distance is harder to interpret than a single Mahalanobis or cosine metric.
- With few labeled pairs or triplets, the learned combination weights and the base learners can overfit when they share the same training constraints.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- May reduce the variance of the learned distance compared with a single metric learner, particularly when the base learners make partly independent errors.
- Lets each base metric specialise on a feature subspace, which can help when the feature set is heterogeneous.
- Works with any metric learning algorithm that produces a distance on pairs, so the base learners can be swapped.
- Disagreement among base metrics can flag pairs whose similarity is unclear, which is a heuristic signal and not a calibrated uncertainty estimate.
- Because the output is a single distance function, it can replace the default distance in an existing retrieval or nearest-neighbor pipeline without changing the rest of that pipeline.
Applications
- Nearest-neighbor classification on tabular data or image embeddings where the default distance is a poor fit.
- Information retrieval and ranking, where the similarity function determines the result order.
- Few-shot learning with limited labeled examples, where variance in the similarity estimate is a concern.
- Clustering pipelines that use a learned distance in place of Euclidean distance.
How it works
How it works
A set of K base metric learners, such as LMNN, ITML, Mahalanobis metric learners, or neural embedding networks, are trained separately. Each can be fitted on the full data or on a random feature subspace or bootstrap sample to encourage diversity.
Diversity among base metrics is promoted by varying the feature subset, the training constraints, the sampled similar and dissimilar pairs, or the random seed. Diversity is the key requirement: if the base metrics agree closely, the ensemble adds little over a single learner. To check diversity, compute on validation data the overlap or rank correlation of the k nearest neighbours returned by each base metric for the same queries. Near-identical neighbour lists mean the ensemble is unlikely to add much; low agreement is necessary but not sufficient for a gain.
The K learned distances are combined into one metric using the weighted sum d_ens(x, x') = Σ_k w_k d_k(x, x'). Before summation, each d_k must be normalised to a comparable scale, for example by dividing it by its mean over validation pairs, because otherwise the metric with the largest raw values dominates the sum. The weights are non-negative; uniform averaging sets w_k = 1/K, so the weights sum to one. Other weights may be chosen by optimising a validation criterion such as k-NN accuracy. Combining kernel matrices is a related but different operation, and the formula above does not describe it. The combined distance then replaces a hand-crafted distance.
Formula
d_{\text{ens}}(x,x') = \sum_{k=1}^{K} w_k \, d_k(x,x')The ensemble distance is used in a downstream task such as nearest-neighbor classification, information retrieval, clustering, or few-shot learning, in place of or alongside the original Euclidean or cosine distance. Performance is measured on held-out data with the task's own metric, such as accuracy or MAP.
Common pitfalls
- Using base learners with the same hyperparameters and data views, which produces highly correlated metrics that add no diversity.
- Setting combination weights without a validation split that reflects the downstream task, such as k-NN accuracy or retrieval MAP.
- Combining distances from features on very different scales without normalising the pairwise distances first.
- Evaluating on the training pairs rather than on a held-out retrieval or classification benchmark.
- Treating the method as simple feature concatenation, which does not learn a distance and does not adjust for how the features interact.
Frequently asked questions
How many base metrics should I use?
No fixed number of base metrics is standard. Start with a small ensemble, add base learners, and stop when validation performance levels off, since each added learner increases training cost.
How should I combine the base metrics?
Uniform averaging of the distances is a simple baseline. If you have a validation set with labeled pairs, you can choose combination weights that minimise validation k-NN error or maximise retrieval MAP. Any weight-learning procedure should be validated on data not used to train the base learners.
Is ensemble metric learning the same as learning a kernel ensemble?
They are related but not equivalent. A Mahalanobis metric can be written as a linear kernel on transformed features, so the two views share a foundation. The formula above averages unsquared distances. Because each distance is the square root of a function that is linear in the kernel values, averaging distances and averaging kernel matrices generally produce different combined similarities.
Can I apply ensemble metric learning to few-shot scenarios?
Yes. Base metrics can be trained on different episode partitions or with different backbones, and the combined similarity can be used for nearest-neighbor classification. Whether it outperforms a well-regularised single learner depends on the data and must be checked on held-out episodes.
When is a single metric learner sufficient?
When the labeled training data is large relative to the feature space, a single well-regularised metric learner may perform close to an ensemble. The ensemble is most likely to help when labeled data is small, the features are high-dimensional, or the query distribution is heterogeneous.
Related methods
Sources
Wang, J., Kalousis, A., & Woznica, A. (2012). Parametric local metric learning for nearest neighbor classification. Advances in Neural Information Processing Systems, 25.
Open publication referenceSimilarity learning. Wikipedia.
Open publication reference