Principled Algorithms for Optimizing Generalized Metrics in Binary Classification

Anqi Mao, Mehryar Mohri, Yutao Zhong

Introduction

In many critical machine learning applications, such as medical diagnosis, fraud detection, and information retrieval, standard accuracy is an insufficient measure of performance. These domains often involve highly imbalanced datasets where a model can achieve high accuracy simply by predicting the majority class, while failing to identify the rare but significant "positive" instances. To address this, practitioners rely on generalized metrics—such as the $F_1$-score, $F_\beta$-measure, and the Jaccard index—which provide a more nuanced balance between precision and recall.

Despite their widespread use, directly optimizing these metrics is computationally challenging. This paper introduces METRO (Metric Optimization), a principled framework designed to optimize complex classification metrics within specific, restricted hypothesis classes. By moving beyond simple threshold-tuning, METRO provides strong theoretical guarantees and superior empirical performance.

The Challenge of Linear-Fractional Metrics

Generalized metrics are typically linear-fractional, meaning they are defined as a ratio of linear combinations of the confusion matrix entries (True Positives, False Positives, False Negatives, and True Negatives). For example, the $F_1$-score is the harmonic mean of precision and recall, represented as a ratio where the numerator and denominator both depend on the model's predictions.

Most existing approaches to this problem follow a "plug-in" strategy: first, they estimate the conditional probability of a positive label, and then they search for an optimal threshold to apply to those probabilities. However, the authors identify two critical flaws in this paradigm:

  1. Model Constraints: Plug-in methods assume the model can perfectly estimate probabilities (the Bayes-optimal case). In practice, we use restricted hypothesis classes $\mathcal{H}$ (like linear classifiers or specific neural network architectures) that may never contain the true probability distribution. In these cases, the best model for a metric might require a different orientation or structure, not just a different threshold.
  2. Lack of Finite-Sample Guarantees: Many existing methods only offer "asymptotic" consistency, meaning they work given infinite data. They provide little guidance on how the algorithm will perform with the limited datasets encountered in the real world.

The METRO Framework

METRO addresses these issues by transforming the optimization of a ratio into a generalized cost-sensitive learning problem. The framework is built on three pillars:

1. Reformulation

The authors prove that minimizing a generalized metric is equivalent to finding an optimal weighting parameter $\lambda^*$ and minimizing a corresponding weighted cost-sensitive loss function. This shift allows the problem to be treated as a series of more standard classification tasks.

2. Surrogate Losses

Because the target cost-sensitive loss (based on the 0-1 loss) is non-differentiable and NP-hard to optimize, METRO employs a family of "surrogate" losses. By using cost-sensitive versions of Logistic or Hinge loss, the framework makes the problem amenable to standard optimization techniques like Stochastic Gradient Descent (SGD).

3. $\mathcal{H}$-Consistency

The core theoretical contribution of this work is the proof of $\mathcal{H}$-consistency. The authors demonstrate that by minimizing their surrogate loss, the algorithm is guaranteed to minimize the actual target metric for the specific hypothesis set $\mathcal{H}$ being used. Crucially, they provide finite-sample generalization bounds, giving practitioners confidence in the model's performance even with limited data.

The METRO Algorithm

The researchers propose two implementations of METRO:

  • METRO-B: Uses a binary search to efficiently find the optimal weighting $\lambda^*$.
  • METRO-C: Employs cross-validation to select the best parameter.

Both versions are designed to be computationally efficient, with a training overhead comparable to that of a standard classifier.

Experimental Evaluation

The authors evaluated METRO against standard Empirical Risk Minimization (ERM) and state-of-the-art baselines on several image classification benchmarks, including CIFAR-10, CIFAR-100, and SVHN. To test the metrics, they adapted these datasets into binary tasks by selecting specific class pairs.

Key Findings

  • Superior Performance: METRO consistently outperformed baselines across a variety of metrics ($F_1, F_{0.5}, F_{1.5}$, and Jaccard). For instance, on the CIFAR-10 Jaccard index task, METRO achieved a score of 0.6575, significantly outperforming the best baseline at 0.6428.
  • The Thresholding Fallacy: Through simulated 2D datasets, the authors demonstrated that in restricted model spaces, the optimal model for a metric like $F_\beta$ often has a different slope or orientation than a standard classifier. This confirms that simply shifting the threshold of a standard SVM or Logistic Regression is fundamentally insufficient.
  • Scalability: The framework proved robust across different datasets and metrics, maintaining computational efficiency even when integrated with deep neural networks.

Conclusion and Future Work

METRO provides a mathematically rigorous and practically viable framework for optimizing the metrics that actually matter in imbalanced classification. By focusing on $\mathcal{H}$-consistency rather than asymptotic behavior, the authors bridge the gap between theoretical machine learning and real-world application.

While the current framework is highly effective for binary classification, future research may extend these principled approaches to multi-class and multi-label settings. Additionally, the authors note that in extremely over-parameterized regimes, the current theoretical bounds may become loose, suggesting a need for further refinement in the context of very large-scale deep learning models.

Summary updated

BibTeX
@inproceedings{mao2025principled,
  author = {Anqi Mao and Mehryar Mohri and Yutao Zhong},
  title = {{Principled Algorithms for Optimizing Generalized Metrics in Binary Classification}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=YngQelHz1X},
}
Figure