Doheon Han, Nuno Moniz, Nitesh V. Chawla
Abstract
Most evaluation metrics for binary classification are derived from the confusion matrix, which is inherently non-differentiable because it relies on discrete predictions. This limits their direct use as loss functions in gradient-based learning, creating a mismatch between training objectives and evaluation criteria. To that end, we offer a general-purpose approach, AnyLoss, that transforms any confusion-matrix-based metric into a differentiable loss function. AnyLoss employs a distinct approximation strategy to estimate a specific, targeted metric score for the prediction model. This is followed by a theoretical and practical analysis of the method, which involves conducting extensive experiments with neural network architectures ranging from simple to advanced across diverse data modalities, including tabular, image, and text. The experimental results demonstrate the generality of our new method, which can target any evaluation metrics derived from a confusion matrix, and highlight that it excels at handling imbalanced datasets.
Citation format
HAN, Doheon; MONIZ, Nuno; CHAWLA, Nitesh V. Generation of loss functions from matrix-based binary classification metrics. ACM Transactions on Knowledge Discovery from Data, 2026, 20(5): 1–40.