# AnyLoss: Transforming Classification Metrics into Loss Functions

arXiv: https://arxiv.org/abs/2405.14745 · HTML: https://mlsanity.com/paper/2405.14745/

## Key facts

- Cited by 3 papers in the map (data through 14 Oct 2026).
- Builds on 8 of its 27 references that are in the map.
- First posted on arXiv 23 May 2024.

## Builds on (most cited first, 8 of 8)

- [Deep Residual Learning for Image Recognition](https://mlsanity.com/paper/1512.03385/) (2015)
- [Model Evaluation, Model Selection, and Algorithm Selection in Machine Learning](https://mlsanity.com/paper/1811.12808/) (2018)
- [Time for a change: a tutorial for comparing multiple classifiers through Bayesian analysis](https://mlsanity.com/paper/1606.04316/) (2016)
- [On Loss Functions for Deep Neural Networks in Classification](https://mlsanity.com/paper/1702.05659/) (2017)
- [sigmoidF1: A Smooth F1 Score Surrogate Loss for Multilabel Classification](https://mlsanity.com/paper/2108.10566/) (2021)
- [Score-oriented loss (SOL) functions](https://mlsanity.com/paper/2103.15522/) (2021)
- [MetricOpt: Learning to Optimize Black-Box Evaluation Metrics](https://mlsanity.com/paper/2104.10631/) (2021)
- [A surrogate loss function for optimization of Fβ score in binary classification with imbalanced data](https://mlsanity.com/paper/2104.01459/) (2021)

## Built on by (most cited first, 3 of 3)

- [The Multiclass Score-Oriented Loss (MultiSOL) on the Simplex](https://mlsanity.com/paper/2511.22587/) (2025)
- [What Do Students Learn? A Feature-Level Analysis of Dark Knowledge](https://mlsanity.com/paper/2606.03052/) (2026)
- [SoftMCC: An MCC-Brier Calibration Bridge for Threshold-Free Model Selection under Class Imbalance](https://mlsanity.com/paper/2608.08984/) (2026)

## Abstract (arXiv)

Many evaluation metrics can be used to assess the performance of models in binary classification tasks. However, most of them are derived from a confusion matrix in a non-differentiable form, making it very difficult to generate a differentiable loss function that could directly optimize them. The lack of solutions to bridge this challenge not only hinders our ability to solve difficult tasks, such as imbalanced learning, but also requires the deployment of computationally expensive hyperparameter search processes in model selection. In this paper, we propose a general-purpose approach that transforms any confusion matrix-based metric into a loss function, textitAnyLoss, that is available in optimization processes. To this end, we use an approximation function to make a confusion matrix represented in a differentiable form, and this approach enables any confusion matrix-based metric to be directly used as a loss function. The mechanism of the approximation function is provided to ensure its operability and the differentiability of our loss functions is proved by suggesting their derivatives. We conduct extensive experiments under diverse neural networks with many datasets, and we demonstrate their general availability to target any confusion matrix-based metrics. Our method, especially, shows outstanding achievements in dealing with imbalanced datasets, and its competitive learning speed, compared to multiple baseline models, underscores its efficiency.
