Optimal Binary Classification Beyond Accuracy
Abstract
The vast majority of statistical theory on binary classification characterizes performance in terms of accuracy.
However, accuracy is known in many cases to poorly reflect the practical consequences of classification error, most famously in imbalanced binary classification, where data are dominated by samples from one of two classes.
The first part of this paper derives a novel generalization of the Bayes-optimal classifier from accuracy to any performance metric computed from the confusion matrix.
Specifically, this result (a) demonstrates that stochastic classifiers sometimes outperform the best possible deterministic classifier and (b) removes an empirically unverifiable absolute continuity assumption that is poorly understood but pervades existing results.
We then demonstrate how to use this generalized Bayes classifier to obtain regret bounds in terms of the error of estimating regression functions under uniform loss.
Finally, we use these results to develop some of the first finite-sample statistical guarantees specific to imbalanced binary classification.
Specifically, we demonstrate that optimal classification performance depends on properties of class imbalance, such as a novel notion called Uniform
Class Imbalance, that have not previously been formalized.
We further illustrate these contributions numerically in the case of k -nearest neighbor classification.
Introduction
Many binary classification problems exhibit class imbalance, in which one of the two classes vastly outnumbers the other.
Classifiers that perform well with balanced classes routinely fail for imbalanced classes, and developing reliable techniques for classification in the presence of severe class imbalance remains a challenging area of research
[He and Ma, 2013, Krawczyk, 2016, Fernández et al., 2018].
Many practical approaches have been proposed to improve performance under class imbalance, including reweighting plug-in estimates of class probabilities [Lewis, 1995], resampling data to improve class imbalance [Chawla et al., 2002] or reformulating classification algorithms to optimize different performance metrics [Dembczynski et al., 2013, Fathony and Kolter, 2019, Joachims, 2005].
Extensive discussion of practical methods for handling class imbalance are surveyed in the books of
He and Ma [2013] and Fernández et al.
Despite the pervasive challenge of class imbalance, our theoretical understanding of class imbalance is limited.
The vast majority of theoretical performance guarantees for classification characterize classification accuracy or, equivalently, misclassification risk [Mohri et al., 2018], which is typically an uninformative measure of performance for imbalanced classes.
Under measures that are used with imbalanced classes in practice, such as precision, recall, F β scores, and class-weighted scores [Van Rijsbergen, 1974, 1979], existing theoretical guarantees are limited to statistical consistency, in that the algorithm under consideration asymptotically optimizes the metric of choice
[Koyejo et al., 2014,
Menon et al., 2013, Narasimhan et al., 2014]; specifically, there is no finite-sample theory that would allow comparison of an algorithm’s performance to that of other algorithms or to theoretically optimal performance levels.
Additionally, existing theory for classification does not explicitly model the effects of class imbalance, especially severe imbalance (i.e., as the proportion of samples from the rare class vanishes), and hence sheds little light on how severe imbalance influences optimal classification.
This paper provides two main contributions.
First, in Section 4, we provide a novel characterization of classifiers optimizing general performance metrics that are functions of a classifier’s confusion matrix.
This characterization generalizes a classical result, that the Bayes classifier optimizes classification accuracy, to a much larger class of performance measures, including those commonly used in imbalanced classification, while relaxing certain empirically unverifiable distributional assumptions that pervade existing such results.
Interestingly, we show that, in general, a Bayes classifier always exists if one considers stochastic classifiers, but not if one considers only deterministic classifiers.
We then use this result to provide relative performance guarantees under these more general performance measures, in terms of the error of estimating the class probability (regression) function under uniform ( L 8 ) loss.
This motivates our second main contribution: an analysis of k -nearest neighbor ( k NN) classification under uniform loss.
In doing so, we also propose an explicit model of a sub-type of class imbalance, which we call Uniform Class Imbalance, and we show that the k NN classifier behaves quite differently under Uniform Class Imbalance than under other sub-types of class imbalance.
To the best of our knowledge, such sub-types of class imbalance have not previously been distinguished in either the theoretical or practical literature, and we hope that identifying such relevant features of imbalanced datasets may facilitate development of classifiers that perform well on specific imbalance problems of practical importance.
Collectively, these contributions provide some of the first finite-sample performance guarantees for nonparametric binary classification under performance metrics that are appropriate for imbalanced data and show how optimal performance depends on the nature of imbalance in the data.
Related Work
Here, we discuss how our results relate to existing theoretical guarantees for imbalanced binary classification and prior analyses of k NN methods.
2.1 Theoretical Guarantees for Imbalanced Binary Classification
Statistical learning theory has studied classification extensively in terms of accuracy [Mohri et al., 2018].
However, when classes are severely imbalanced, accuracy ceases to be an informative measure of performance [Cortes and Mohri, 2004], necessitating guarantees in terms of other performance metrics.
Several papers have sought to address this [Narasimhan et al., 2014, 2015, Koyejo et al., 2014, Yan et al., 2018, Wang et al., 2019a] by generalizing the Bayes optimal classifier, a well-known classifier that provably optimizes accuracy, to more general performance measures better reflecting the desiderata of imbalanced classification.
Relatedly, several works have investigated relationships between these different performance measures and demonstrated that they differ essentially in how they determine the optimal threshold between the two classes [Flach, 2003, Hernández-Orallo et al., 2013, Flach, 2016].
However, existing results make empirically unverifiable assumptions about the distribution of the data, leaving questions about their relevance to real data.
We discuss these assumptions in detail in Section 4, where our main result, Theorem 3, leverages the idea of stochastic thresholding to relax these assumptions.
Another body of closely related theoretical work studies Neyman-Pearson classification, which attempts to minimize misclassification error on one class subject to constraints on misclassification error on other classes, analogous to the approach of statistical hypothesis testing.
While substantial theoretical guarantees do exist for Neyman-Pearson classification [Rigollet and Tong, 2011, Tong, 2013, Tong et al., 2016], these focus on performance within the Neyman-Pearson framework, rather than under general performance measures as in our work, and we know of no work considering stochastic classification under the Neyman-Pearson framework.
Interestingly, our use of stochastic classifiers in Theorem 3 parallels classical results in hypothesis testing [Lehmann and Romano, 2006], and our proof of Theorem 3 involves a reduction (Lemma 22 in the Appendix) of optimization of general classification performance measures to Neyman-Pearson classification.
Meanwhile, many practical approaches to handling class imbalance, such as class-weighting and resampling have been proposed, but the theoretical understanding of these methods is limited.
Class-weighting is a natural choice in applications where costs, or cost ratios [Flach, 2003], can be explicitly assigned and, in the case of binary classification, is statistically equivalent to threshold selection, which we discuss later in this paper
[Scott, 2012].
In practice, resampling appears to be the most popular approach to handling class imbalance
[He and Ma, 2013].
Undersampling the dominant class is straightforward and can provide computational benefits with little loss in statistical performance [Fithian and Hastie, 2014], while interest in oversampling rare classes, sometimes referred to as data augmentation, has grown with the advent of sophisticated generative models to produce additional data [Mariani et al., 2018].
However, the theoretical ramifications of oversampling techniques used for imbalanced classification, most commonly variants of SMOTE [Chawla et al., 2002], are poorly understood.
2.2 k NN Classification and Regression
The k NN classifier is one of the oldest and most well-studied nonparametric classifiers Fix and
Hodges [1951].
Early theoretical results include, Cover and Hart [1967], who showed that the misclassification risk of the k NN classifier with k “ 1 is at most twice that of the Bayes-optimal classifier, and Stone [1977], who showed that the k NN classifier is Bayes-consistent if k Ñ 8 and k { n Ñ 0 .
Extensive literature on the accuracy of k NN classification has since developed [Devroye et al., 1996, Györfi et al., 2002, Samworth, 2012, Chaudhuri and Dasgupta, 2014, Gottlieb et al., 2014, Biau and Devroye, 2015, Gadat et al., 2016, Döring et al., 2018, Kontorovich and Weiss, 2015,
Gottlieb et al., 2018, Cannings et al., 2019, Hanneke et al., 2020].
Rather than accuracy bounds for k NN classification, the bounds on uniform error we present in
Section 5 are most closely related to risk bounds for k NN regression, of which the results of Biau et al.
[2010] are representative.
Biau et al.
[2010] gives convergence rates for k NN regression in
L 2 risk, weighted by the covariate distribution, in terms of noise variance and covering numbers of the covariate space.
While closely related to our bounds on uniform ( L 8 ) risk, their results differ in at least three main ways.
First, minimax rates under L 8 risk are necessarily worse than under Lrisk by a logarithmic factor, as implied by our lower bounds.
Second, the fact that Biau et al.
[2010] use a risk that is weighted by the covariate distribution allows them to avoid our assumption that the covariate density is lower bounded away from 0 , whereas, the lower boundedness assumption is unavoidable under L 8 risk.
Finally, Biau et al.
[2010] assume additive noise with finite variance;
Bernoulli noise is crucial for us to model severe class imbalance.
Extensive research on k NN for imbalanced classification has focused on algorithmic modifications, which are surveyed by Fernández et al.
Examples include prototype selection [Liu and
Chawla, 2011, López et al., 2014, Vluymans et al., 2016], and gravitational methods [Cano et al., 2013, Zhu et al., 2015].
We are aware of no statistical guarantees exist for such methods.
Setup and Notation
Let p X , ρ q be a separable metric space, and let Y “ t 0 , 1 u denote the set of classes.
For any x P X and ϵ ą 0 , B p x, ϵ q : “ t z P X : ρ p x, z q ă ϵ u denotes the open radius-
ϵ ball around x .
Consider n independent samples p X 1 , Y 1 q , . .
, p X n , Y n q drawn from a distribution P X,Y on
X ˆ Y with marginals P X and P Y .
For positive sequences t a n u 8 i “ 1 and t b n u 8 i “ 1 , a n — b n means lim inf n Ñ8 a n { b n ą
and lim sup n Ñ8 a n { b n ă 8 .
To optimize general performance metrics, we must consider stochastic classifiers.
Formally, letting
B : “ t Y „ Bernoulli p
p
q : p P r 0 , 1 su denote the set of binary random variables, a stochastic classifier can be modeled as a mapping p Y :
X Ñ B , where, for any x P X , E r p
Y
p x qs is the probability that the classifier assigns x to class 1 .
We use SC to denote the class of stochastic classifiers.
The true regression function η ˚ : X Ñ r 0 , 1 s is defined as η ˚ p x q : “ P r Y “ 1 | X “ x s “ E r Y | X “ x s ; that is, given an instance X i , the label Y
i is Bernoulli-distributed with mean η p
X i q .
As we show in the next section, an optimal classifier can always be written in terms of the true regression function η , motivating estimates p η : X Ñ r 0 , 1 s of η .
Such estimates p η are referred to as “regressors”.
Optimal Classification Beyond Accuracy
A famous result states that classification accuracy is maximized by the “Bayes” classifier
[Equation]
Here, p Y p x q is simply a constant (deterministic) random variable that takes either the value 0 or the value 1 with probability 1 (depending on η ˚ p x q ).
Our reason for writing Eq.
(1) in this seemingly redundant way will become clear with Definition 2 below.
Although η ˚ is unknown in practice, this result is a cornerstone of the statistical theory of binary classification because it provides an optimal performance benchmark against which a classifier can be evaluated in terms of accuracy [Devroye et al., 1996, Mitchell, 1997, James et al., 2013].
As discussed previously, accuracy can be a poor measure of performance in the imbalanced case.
Therefore, the main contribution of this section, provided in Theorem 3 below, is to generalize this result to a broad class of classification performance measures, including those commonly used in imbalanced classification.
First, we specify performance measures for which our results apply.
4.1 Confusion Matrix Measures (CMMs)
Nearly all measures of classification performance, including accuracy, precision, recall, F β scores, and others, can be computed from the confusion matrix, which counts the number of test samples in each p true class, estimated class q pair.
Formally, let C : “ t C P r 0 , 1 s 2 ˆ 2 : C 1 , 1 ` C 1 , 2 ` C 2 , 1 ` C 2 , 2 “ 1 u denote the set of all possible binary confusion matrices.
Given a classifier p Y , the confusion matrix
C p Y P C and empirical confusion matrix
p C p Y P C are given by
[Equation]
wherein the true positive probability TP p Y and empirical true positive probability x TP p Y are given by
[Equation]
q ı , x TP
[Equation]
Y
[Equation]
n ÿ i
[Equation]
Y i p
Y p
X i q , (3) and
the true and empirical false positive (FP p Y and x FP p Y ), false negative (FN p Y and x FN p Y ), and true positive (TP p Y and x TP p Y ) probabilities are defined similarly.
Note that the expectation in Eq.
(3) is over randomness both in the data and in the classifier.
Intuitively, measures of a classifier’s performance should improve as TN and TP increase and FN and
FP decrease.
We therefore define the class of Confusion Matrix Measures (CMMs) as follows:
Definition 1 (Confusion Matrix Measure (CMM)) .
A function M : C Ñ R is called a confusion matrix measure (CMM) if, for any confusion matrix
[Equation]
, we have M p C
[Equation]
ď
[Equation]
ϵ
[Equation]
Essentially, correcting an incorrect classification should not reduce a CMM.
This is true of any reasonable measure of classification performance, and hence analyzing CMMs allows us to obtain theoretical guarantees for all performance measures used in practice.
Specifically, by evaluating their gradients in the directions “
[Equation]
and “ 0 0 ´ 1 1 ‰ , one can verify that most performance measures, such as weighted accuracy, precision, recall, F β scores, and Matthew’s Correlation Coefficient are
CMMs.
We note that the area under receiver operating characteristic (AUROC) and area under precision-recall curve (AUPRC) are not CMMs because they evaluate ( R -valued) scoring functions rather than ( t 0 , 1 u -valued) classification functions.
However, both AUROC and AUPR are averages of CMMs computed at various classification thresholds, and, as we discuss in Appendix A.1, our results for CMMs thus imply similar results for these measures.
We next present our main result of
Section 4, which generalizes the Bayes classifier (1) to arbitrary CMMs.
4.2 Generalizing the Bayes Classifier
The Bayes classifier thresholds the regression function deterministically at the value 0 .
The following generalizes this to a stochastic threshold:
Definition 2 (Regression-Thresholding Classifier (RTC)) .
A classifier p Y :
X Ñ B is called a regression-thresholding classifier (RTC) if, for some p, t P r 0 , 1 s and η : X Ñ r 0 , 1 s ,
[Equation]
for all x P X .
In the sequel, we will denote such classifiers p Y p,t,η , and refer to the pair p t, p q as the threshold .
Now we can state the main result of this paper:
Theorem 3.
For any CMM M and stochastic classifier p Y , there is an RTC p Y p,t,η with M p p Y p,t,η q ě
M p p Y q .
In particular, if M is maximized by any stochastic classifier, then M is maximized by a RTC.
As a special case of Theorem 3, the classical Bayes classifier corresponds to M p C q “ TN ` TP, p “ 0 , and t “ 0 . 5 .
However, as discussed in the next paragraph, without stronger assumptions,
Theorem 3 does not hold for deterministic classifiers.
Since RTCs generalize both the RTC structure and optimality properties of the Bayes classifier, we also refer to them as generalized Bayes classifiers .
We note that existence of any maximizer p Y of M p C p
Y q may depend on specific properties, such as (semi)continuity or convexity of M , which we do not investigate here.
We emphasize that Theorem 3 makes absolutely no assumptions on the distribution of the data.
In particular, all prior characterizations of optimal classifiers under general performance metrics assume that the distribution of the class probability η p X q is absolutely continuous [Narasimhan et al., 2014, 2015, Koyejo et al., 2014, Yan et al., 2018, Wang et al., 2019a] 2 , and Wang et al.
[2019a] claim that regularity assumptions on η p
X q such as absolute continuity “seem to be unavoidable”.
Our
Theorem 3 is the first result to omit such assumptions, and we specifically show that this comes at the cost of the optimal classifier possibly being non-deterministic for a single atom of η p X q .
Figurevisually compares the stochastic thresholding classifier in Theorem 3 to prior approaches.
[Figure]
Koyejo et al
2014], Narasimhan et al
2014] and others have suggested using other Deterministic thresholds (e.g., η p x q optimize η p q is
Wang et al.
[2019a] showed that the optimal classifier can always be written as a Mixture of Deterministic (MD) classifiers (e.g., a p 0 .
7 q -mixture of thresholds at η p x q “ 0 . 2 and η p x q “ 0 . 4 , shown here).
Finally, we propose using a single Stochastic threshold (e.g., p t, p q “ p 0 .
75 q , shown here).
Only MD and Stochastic approaches are optimal in general (for arbitrary CMMs, without η p X q absolutely continuous), while Stochastic thresholding is strictly simpler than MD.
The generality of Theorem 3 necessitates a significantly more complex proof than prior work.
In particular, we prove Theorem 3 in Appendix A using a series of variational arguments.
Roughly speaking, given a classifier p Y , we construct a perturbation p Y 1 of p Y
such that either M p C p
Y q ă
M p C p Y 1 q or p Y 1 is an RTC and M p C
p Y q ď M p C p Y 1 q .
Since, the classifier p Y might be quite poorly behaved (e.g., its behavior on sets of P X -measure 0 could be arbitrary), the technical complexity lies in constructing admissible perturbations (i.e., those that are well-defined classifiers).
For this reason, the proof of Theorem 3 involves a series of constructions of increasingly well-behaved classifiers.
Theorem 3 tells us that a generalized Bayes classifier can always be written in terms of the regression function η and two scalar parameters p t, p q depending on the distribution of η p X q and the CMM M .
The next example shows that this characterization cannot be simplified without stronger assumptions:
Example 4.
Suppose X “ t 0 u is a singleton, η p 0 q P p 0 , 1 q , and, for some θ ą 0 , M p C q “ p TP q θ TN.
One can check that M is a valid CMM.
Suppose p Y is an RTC.
It is straightforward to compute that
M p C p
Y q “ p pη p
qq θ p 1 ´ p qp 1 ´ η p 0 qq 1 t t “ η p 0 qu , and that
M p C p
Y q is uniquely maximized by p “ θθ ` 1 P p 0 , 1 q and t “ η p 0 q P p 0 , 1 q .
This shows that both threshold parameters p and t in an RTC are necessary, in the absence of further assumptions on M or η .
This example also illustrates the need for stochasticity to optimize general CMMs.
Specifically, for any deterministic classifier p Y , either p Y p 0 q “ 0 (so TP “ 0 ) or p Y p 0 q “ 1 (so TN “ 0 )
; in either case, M p C p Y q “ 0 .
This performance gap between stochastic and deterministic classifiers is closely related to Theorem 1 of Cotter et al.
[2019b], which provides a closely related lower bound on how well a stochastic classifier can be approximated by a deterministic one, in terms of the probability assigned to atoms of η p X q .
However, Cotter et al.
[2019b] only study how well stochastic classifiers can be approximated by deterministic ones (with the motivation of derandomizing classifiers), not whether stochastic classifiers can systematically outperform deterministic ones, as we show here.
4.3 Relative Performance Guarantees in terms of the Generalized Bayes Classifier
Theorem 3 motivates a two-step approach to imbalanced classification in which one first estimates the regression function η and then selects a stochastic threshold p t, p q that optimizes empirical performance M p
p C p
Y q .
Such an approach has many practical advantages.
For example, as we show in Appendix D, a simple algorithm can exactly optimize the threshold p t, p q over large datasets in
O p n log n q time.
Additionally, one can address covariate shift or retune a classifier trained under one
CMM to perform well under another CMM, simply by re-optimizing p t, p q , which is statistically and computationally much easier than retraining a classifier from scratch.
In this section, we focus on an advantage for theoretical analysis, namely that the error of such a classifier decomposes into errors in selecting p t, p q and errors in estimating η , allowing the derivation of performance guarantees relative a generalized Bayes classifier.
All results in this section are proven in Appendix B.
We first bound the performance difference of thresholding two regressors in terms of their Ldistance.
This will allow us to bound error due to using a regressor p η instead of the true η .
Lemma 5.
For
[Equation]
Intuitively, Lemma 5 bounds the largest difference in the confusion matrices of p Y p,t,η and p Y p,t,ηby the probability that the threshold t lies between η and η 1 .
As we will show later, under a margin assumption, this can be bounded by the L 8 distance between η and η 1 .
Our next lemma bounds the worst-case error over thresholds p t, p q P r 0 , 1 s of the empirical confusion matrix.
This allows us to bound error due to using an empirical threshold p p t, p p q instead of the threshold p t ˚ , p ˚ q that is optimal for the true regression function.
Lemma 6.
Let η : X Ñ r 0 , 1 s be any regression function.
Then, with probability at least 1 ´ δ ,
[Equation]
p
[Equation]
Lemma 6 follows from Vapnik-Chervonenkis (VC) bounds on the complexity of the set t p Y p,t,η : p, t P r 0 , 1 su of possible RTCs with fixed regression function η .
In fact, Appendix B proves a more general bound on the error between empirical and true confusion matrices uniformly over any family
F of stochastic classifiers in terms of the growth function of F .
Consequently, when F has finite VC dimension, we obtain uniform convergence at the fast rate a log p n { δ q{ n .
As we formalize later, this suggests that the difficulty in tuning an imbalanced classifier to optimize a CMM M comes not from difficulty in estimating the confusion matrix but rather from the sensitivity of commonly used CMMs to the selected threshold.
Because Theorem 3 shows that any CMM can be optimized by a RTC, we state here only the specific result for RTCs.
Before combining Lemmas 5 and 6 to give the main result of this section, we note a margin assumption, which characterizes separation between the two classes:
Definition 7 (Tsybakov Margin Condition) .
Let C, β ě 0 , t P p 0 , 1 q .
A classification problem with covariate distribution P X and regression function η satisfies a p C, β q -margin condition around t if, for any ϵ ą 0 , P r| η p X q ´ t |
ď ϵ s ď Cϵ β .
The Tsybakov margin condition, introduced by Mammen and Tsybakov [1999] for t “ 0 . 5 , is widely used to establish convergence rates for classification in terms of accuracy [Audibert and Tsybakov, 2007, Arlot and Bartlett, 2011, Chaudhuri and Dasgupta, 2014].
Together with the margin condition and a Lipschitz condition on the M , Lemmas 5 and 6 give the following bound on sub-optimality of an RTC if the threshold is selected by maximizing M over the empirical confusion matrix:
Corollary 8.
Let η : X Ñ r 0 , 1 s be the true regression function and p η : X Ñ r 0 , 1 s be any regressor.
Let
[Equation]
¯ and
[Equation]
¯ denote the empirical and true optimal thresholds, respectively.
Suppose M is Lipschitz continuous with constant L M with respect to the uniform ( L 8 ) metric on C .
Finally, suppose P X and η satisfy a p C, β q -margin condition around t ˚ .
Then, with probability ě 1 ´ δ ,
M ´
C p Y p ˚ ,t ˚ ,η ¯ ´ M ´
C p Y p p, p t, p η ¯ ď L M ˜
C } η ´ p η } β 8 `c n log 32 p 2 n ` 1 q δ ¸ .
Uniform Error of the k NN Regressor
In the previous section, we bounded relative performance of an RTC in terms of uniform ( L 8 ) loss of the regression function estimate.
Here, we bound uniform loss of one such regressor, the widely used k -nearest neighbor ( k NN) regressor.
Our analyses include a parameter r , introduced in Section 5, that characterizes a novel sub-type of class imbalance, which we call Uniform Class Imbalance.
This leads to insights about how the behavior of the k NN classifier depends not only on the degree, but also on the structure, of class imbalance in a given dataset.
We begin with some notation:
Definition 9 ( k -Nearest Neighbor Regressor) .
Given a point x P X , let σ p x q denote a permutation of t 1 , ..., n u such that X σ i p x q is the i th -nearest neighbor of x among X 1 , ..., X n .
For integers k P r 1 , n s , the k NN regressor p η k : X Ñ r 0 , 1 s is defined as
[Equation]
We now formalize a novel sub-type of class imbalance:
Definition 10 (Uniform Class Imbalance (UCI)) .
Write the regression function as η “ rζ , where r P p 0 , 1 s and ζ : X Ñ r 0 , 1 s is a regression function with sup x P X ζ p x q “ 1 .
A classification problem has Uniform Class Imbalance (UCI) in the number of samples n if r Ñ 0 as n Ñ 8 .
Intuitively, in UCI, the class Y “ 1 is rare regardless of X .
This includes “difficult” classification problems where the covariate X provides only partial information about the class Y and examples from the rare class lie deep within the distribution of the common class.
Examples include rare disease diagnosis [Schaefer et al., 2020] or fraud detection [Awoyemi et al., 2017].
In practice, the classifier’s role is often to flag “high-risk” samples X , those with η p X q relatively high, for follow-up investigation.
UCI can be distinguished from “easier” problems in which, for some x P X , η p X q «and so, given enough training data, a classifier can confidently assign the label Y “ 1 .
These include well-separated classes or deterministic problems (e.g., protein structure prediction; Noé et al.
To our knowledge, such notions of class imbalance have not previously been distinguished.
In the particular case of data drawn from a logistic model, UCI reduces to the notion of class imbalance described in Wang [2020]; however, UCI applies in more general contexts.
5.1 Uniform Risk Bounds
We now present bounds (proven in Appendix C.1) on uniform error } η ´ p η } 8 “ sup x P X | η p x q´ p η p x q| of the k NN regressor p η k .
First, recall two standard quantities, covering numbers and shattering coefficients, by which we measure complexity of the feature space:
Definition 11 (Covering Number) .
Suppose p X , ρ q is a totally bounded metric space.
Then, for any ϵ ą 0 , the ϵ -covering number N p ϵ q of p X , ρ q is the smallest integer such that there exist N p ϵ q points x 1 , ..., x N p ϵ q P X satisfying X Ď
[Equation]
Definition 12 (Shattering Coefficient) .
For integers n ą 0 , the shattering coefficient of balls in p X , ρ q is S p n q “
[Equation]
We now state two assumptions data distribution P X,Y :
Assumption 13 (Dense Covariates Assumption) .
For some p ˚ , ϵ ˚ , d ą 0 , the marginal distribution P X of covariates is lower bounded, for any x P X and ϵ P p 0 , ϵ ˚ s , by P X
p B ϵ p x qq ě p ˚ ϵ d .
Assumption 13 ensures that each query point’s nearest neighbors are sufficiently near to be informative.
We also assume that the regression function ζ is smooth:
Assumption 14 (Hölder Continuity) .
For some α P p 0 , 1 s , L : “ sup x ‰ x 1 P X | ζ p x q´ ζ p x 1 q | ρ α p x,x 1 q ă
[Equation]
We now state our upper bound on uniform error:
Theorem 15.
Under Assumptions 13 and 14, whenever k { n ď p ˚ p ϵ ˚ q d { 2 , for any δ ą 0 , with probability at least 1 ´ N ´ p 2 k {p p ˚ n qq 1 { d ¯ e ´ k { 4 ´ δ , we have } η ´ p
[Equation]
If r P O pp log S p n q{ n q , this bound is minimized by k — n , giving } η ´ p η } 8 P O P pp log S
p n qq{ n q .
Otherwise, this bound is minimized by k — n 2 α
α ` d p log S p n qq d 2 α ` d r ´ d 2 α ` d , giving
[Equation]
[Equation]
Of the three terms in (5), the first term, of order r p k { n q α { d , comes from smoothing bias of the k NN classifier.
The second and third terms are due to label noise, with the second term dominating under extreme class imbalance r P
O p log S p n q{ n q and the third term dominating otherwise.
Theoremshows that, under UCI, one should use a much larger choice of the tuning parameter k than in the case of balanced classes; indeed, setting k — n
α 2 α ` d p log S
p
n qq d 2 α ` d , which is optimal in the balanced case, gives a rate that is suboptimal by a factor of r ´ d {p 4 α ` d q .
The following example demonstrates how to apply Theorem 15 in a concrete setting of interest:
Corollary 16 (Euclidean, Absolutely Continuous Case) .
Suppose p X , ρ q “ pr 0 , 1 s d , }¨} 2 q is the unit cube in R d , equipped with the Euclidean metric, and P X has a density that is lower bounded away from 0 on X .
Then, for k — n 2 α 2 α ` d p log n q d 2 α ` d r ´ d 2 α ` d
[Equation]
} η ´ p η } 8 P O P
[Equation]
¯ .
The most problematic term in this bound is the exponential dependence on the dimension d of the covariates.
Fortunately, since Theorem 15 utilizes covering numbers, it improves if the covariates exhibit structure, such as that of a low-dimensional manifold.
We illustrate this in detail in Appendix C.1.
We close with a minimax lower bound, proven in Appendix C.2, on the uniform error of any estimator, over p α, L q -Hölder regression functions.
Up to a polylogarithmic factor in r , the rate of this lower bound matches that in Theorem 15, suggesting that both bounds are quite tight.
Theorem 17.
Suppose X “ r 0 , 1 s d is the d -dimensional unit cube and X „ Uniform p X q .
Let Σ
α p
L q denote the family of p α, L q -Hölder continuous regression function.
Then, there exist constants n 0 and c ą 0 (depending only on α , L , and d ) such that, for all n ě n 0 and any estimator p η ,
[Equation]
Discussion Plugging the above upper bounds on } η ´ p η } 8 into Corollary 8 provides error bound under arbitrary CMMs, in terms of the sample size n , hyperparameter k , UCI degree r , and complexity parameters (margin β , smoothness α , intrinsic dimension d , etc.) of X and P X,Y .
Thus, these results collectively give some of the first complete finite-sample guarantees under general performance metrics used for imbalanced classification.
Our analysis shows that, under severe UCI, the optimal k is much larger than in balanced classification, whereas this same k leads to sub-optimal, or even inconsistent, estimates of the regression function under other (nonuniform) forms of class imbalance.
Numerical Experiments
We provide two numerical experiments to illustrate our results from Sections 4 and 5.
We repeat each experiment 100 times and present average results with 95% confidence intervals computed using the central limit theorem.
Python implementations and instructions for reproducing each experiment can be found at https://gitlab.tuebingen.mpg.de/shashank/ imbalanced-binary-classification-experiments .
Further technical details regarding the experiments can be found in Appendix E, while Appendix F explores some predictions of our theoretical results on real data from a credit card fraud detection problem.
Experiment 1 Example 4 showed that, under general CMMs, deterministic RTCs are sometimes unable to approach optimal classification performance, necessitating stochastic RTCs.
This experiment demonstrates this gap numerically.
Suppose X “ r 0 , 1 s , over which X is uniformly distributed, and for all x P X , η p x q “ 0 .
5 ¨ 1 t 1 { 3 ď x ă 2 { 3 u ` 1 t 2 { 3 ď x u .
Consider the CMM M p C q “ TP ¨ TN.
Similar to the analysis in Example 4, the optimal value of M p C q “ p 5 { 12 q 2 “ 25144 is achievable only by a stochastic classifier, whereas as deterministic classifiers achieve at most M p C q “ 1 { 6 ă 25 { 144 .
For 10 logarithmically spaced values of n between 10 2 and 10 4 , we drew n independent samples of p X, Y q according the above distribution.
Using this training data, we selected optimal deterministic and stochastic thresholds t P r 0 , 1 s and p t, p q P r 0 , 1 s 2 for the k NN classifier by maximizing
M p p C q over 10 4 uniformly spaced values in r 0 , 1 s and r 0 , 1 s 2 , respectively.
Since, in this example, α “ d “ 1 , we set k “ t n 2 { 3 u as suggested by Theorem 16.
As another point of comparison, we also include a very different deterministic classifier, a random forest, trained with default parameters of
Python’s scikit-learn package.
We estimated M p C q using 1000 more independently generated test samples of p X, Y q .
Figure 2a shows regret, i.e., sub-optimality of each classifier relative to the optimal classifier, in terms of M p C q .
Consistent with our analysis, regrets of the deterministic classifiers are bounded away from 0 , while regret of the stochastic classifier vanishes as n increases.
Experiment
This experiment demonstrates that making classifiers robust to severe class imbalance requires distinguishing different sub-types of class imbalance, such as UCI.
Suppose X “ r 0 , 1 s ,
X „ Uniform pr 0 , 1 sq , and r P p 0 , 1 q .
Consider two regression functions η 1 p x q “ r p 1 ´ x q and η 2 p x q “ max t 0 , 1 ´ x { r u .
η 1 and η 2 exhibit the same overall class imbalance, with r { 2 proportion of samples from class 1 .
The regression function η 1 satisfies UCI of degree r , whereas η 2 does not satisfy a nontrivial degree of UCI.
For sufficiently small r P p 0 , 1 q , specifically r P o
[Equation]
Theorem 15 gives that the optimal choice of k under η 1 satisfies k P ω p rn q .
On the other hand, if k P ω p rn q , then, under η 2 , E r p η k p 0 qs Ñ 0 , so that p η k p 0 q is an inconsistent estimate of η 2 p 0 q “ 1 .
For 10 logarithmically spaced values of n between 10 2 and 10 4 , we drew n independent samples of p X, Y q according the joint distributions corresponding to each of η 1 and η 2 .
Since, in this example, α “ d “ 1 , to ensure r P o ` n ´ d {p 2 α ` 2 d q ˘ , we set r “ n ´ 1 { 2 .
As indicated by Corollary 16, we set k “ t n 2 { 3 r ´ 1 { 3 u .
We then computed L 8 and L 1 distances between the k NN regressor (Eq.
(4)) and true regression function.
We also drew 1000 independent test samples of p X, Y q and used these to estimate the F 1 score of thresholding the k NN regressor at a threshold t determined by optimizing the
[Figure]
empirical F 1 score (over the training data) over 100 uniformly-spaced values of t P r 0 , 1 s .
Figure 2b shows the uniform ( L 8 ) error, the average ( L 1 ) error, and the F 1 regret, which we bounded in
Corollary 8.
Consistent with our analysis above, the uniform ( L 8 ) error decays to 0 under η 1 but not under η 2 .
Meanwhile, the average error ( L 1 ) decays to 0 under both η 1 and η 2 .
Consistent with
Corollary 8, the F 1 regret of the thresholded classifier, which decays to 0 under η 1 but not under η 2 , mirrors performance of the regressor in uniform ( L 8 ) error rather than average ( L 1 ) error.
Conclusions
Our main conclusions are as follows.
First, without any assumptions on the data-generating distribution, the Bayes-optimal classifier generalizes from accuracy to other performance metrics using a stochastic thresholding procedure, while, in general, deterministic classifiers may not achieve Bayesoptimality.
This generalized Bayes classifier provides an optimal performance benchmark relative to which one can analyze classifiers that threshold estimates of the regression function.
This includes the k NN classifier, for which we provided new guarantees, including minimax-optimally under uniform loss in the presence of Uniform Class Imbalance.
Our results imply that the parameter k needs to be tuned differently for different sub-types of imbalanced classification, suggesting that developing reliable classifiers for severely imbalanced classes may require a more nuanced understanding of the data at hand.
Further work is needed to (a) understand how sub-types of class imbalance can be distinguished in practice, (b) develop adaptive classifiers that perform well under multiple imbalance sub-types, and (c) extend our results to the multiclass case.
While this paper focused on statistical properties of stochastic classification, we should point out that using stochastic classifiers in real applications may require careful consideration of possible downstream consequences.
On one hand, Theorem 3 provides justification for using (a limited degree of) stochasticity to break certain ties between classes: sometimes, this is provably necessary to optimize performance according to certain metrics.
Stochastic classifiers can also be easier to train [Cotter et al., 2019a, Lu et al., 2020] or more robust to adversarial examples [Pinot et al., 2022].
However, stochastic classifiers have risks, including being harder to interpret, explain, or debug, and being vulnerable to manipulation by downstream users (e.g., a user might query the classifier multiple times to produce a desired prediction).
Stochastic classifiers may also violate certain notions of fairness, as individuals with identical features might be assigned to different classes.
Techniques for derandomizing classifiers [Cotter et al., 2019b, Wu et al., 2022] may help address these issues.
Acknowledgments and Disclosure of Funding
This work was supported by the German Federal Ministry of Education and Research (BMBF) through the Tübingen AI Center (FKZ: 01IS18039B).
Checklist
For all authors... (a) Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope?
[Yes] (b) Did you describe the limitations of your work?
[Yes] (c) Did you discuss any potential negative societal impacts of your work?
[N/A] (d) Have you read the ethics review guidelines and ensured that your paper conforms to them?
[Yes] 2.
If you are including theoretical results... (a) Did you state the full set of assumptions of all theoretical results?
[Yes] (b) Did you include complete proofs of all theoretical results?
[Yes] See Appendices A, B, and C. 3.
If you ran experiments...
(a) Did you include the code, data, and instructions needed to reproduce the main experimental results (either in the supplemental material or as a URL)?
[Yes] Code and instructions for reproducing the experimental results are included in the supplemental material.
(b) Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)?
[Yes] (c) Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)?
[Yes] (d) Did you include the total amount of compute and the type of resources used (e.g., type of GPUs, internal cluster, or cloud provider)?
[Yes] See Appendix E. 4.
If you are using existing assets (e.g., code, data, models) or curating/releasing new assets... (a) If your work uses existing assets, did you cite the creators?
[Yes] (b) Did you mention the license of the assets?
[Yes] (c) Did you include any new assets either in the supplemental material or as a URL?
[N/A] (d) Did you discuss whether
and how consent was obtained from people whose data you’re using/curating?
[N/A] (e) Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content?
[N/A] 5.
If you used crowdsourcing or conducted research with human subjects... (a) Did you include the full text of instructions given to participants and screenshots, if applicable?
[N/A] (b) Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable?
[N/A] (c) Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation?
[N/A]
A Derivation of the Generalized Bayes Classifier
In this Appendix, we prove Theorem 3, in which we characterize a stochastic generalization of the
Bayes classifier to arbitrary CMMs.
We reiterate the theorem for the reader here:
Theorem 3.
If argmax p Y P SC M p C p Y q ‰ ∅ , then there exists a regression-thresholding classifier
[Equation]
As described in the main paper, unlike prior results [Koyejo et al., 2014, Yan et al., 2018, Wang et al., 2019b], we do not assume that the distribution of η p X q is absolutely continuous.
This makes proving Theorem considerably more complicated than these previous results.
We prove Theoremin a sequence of steps, constructing optimal classifiers in forms progressively closer to that of the generalized Bayes classifier described in Theorem 3.
Specifically, we first show, in Lemma 18, that there exists an optimal classifier that is a (stochastic) function of the true regression function η ˚ .
We then construct an optimal classifier in which this function of η ˚ is non-decreasing.
Finally, we construct an optimal classifier in which this function of η ˚ is a threshold function, as in Theorem 3.
Lemma 18.
For any stochastic classifier p Y : X Ñ B , there is a stochastic classifier p Y 1 : X Ñ B of the form
[Equation]
6) for some f : r 0 , 1 s Ñ r 0 , 1 s , such that C p Y 1 “ C p Y .
Proof.
We start by defining the regression function and discussing formal probability notation.
Let
F “ σ p η ˚ p Z qq be the σ -field generated by the true regression function η ˚ p Z q .
Define p Y 1 : X Ñ B by
[Equation]
where by the η ˚ p x q we are explicitly indicating that η ˚ p x q is the input to the conditional expectation, as the conditional expectation is a measurable function of η ˚ p Z q .
In the sequel, following standard conventions, we omit such notation.
Note that p Y 1 has the desired form and is defined almost surely.
Now, we get our final notes in place before proceeding with calculations.
Let G “ σ p X q be the σ -field generated by X .
A key step in the proof is showing the equality
[Equation]
We first provide an intuitive summary.
Observe that conditioned on η ˚ p X q , Y is independent of p Y and p Y 1 separately.
Thus, we can integrate over Y and get the η ˚ p X q .
By the definition of p Y 1 we obtain the conditional expectation with respect to Y , and we have the resulting equality.
For the time being, taking Equation (7) as fact, we complete the rest of the proof.
Combining
Equation (7) and the tower property of conditional expectation, we have
[Equation]
Similarly, one can check that C p Y 1 “ C p Y .
Proof of Equation (7) .
We now present the formal details to establish Equation (7), which may be skipped if one is uninterested in the measure-theoretic details.
We first to set up the random variables needed to formalize the above intuition.
Let S , T , U , V , and W be random variables.
Let p S, T q “ p η ˚ p X q , X q .
We also require U and V to be uniform on r 0 , 1 s .
We need not specify the precise distribution W .
Further, let p S, T q , U , V , and W all be independent.
For notation purposes, it is convenient for the underlying probability space p Ω , G , P q to be the product probability space of some probability spaces to the extent possible.
In particular, we require the set Ω “ Ś Wi “ S Ω i and a set B in G to have a product structure B “ Ś Wi “ S B i for ease of exposition.
Note that the measure P is not a product measure, as S and T are dependent, although it is a product measure with respect to the laws of p S, T q , U , V , W .
Now, we define Y , p Y 1 , and p Y in terms of U , V , W , and X .
Define
[Equation]
where here U serves as the noise in Y , V serves as the internal randomization of p Y 1 , and W serves as the possible internal randomization of p Y .
Here, 1 is the indicator taking the value 1 if the event in curly braces occurs and 0 otherwise, and r is some function.
Note that this is still of the desired form.
To prove the first part of Equation (7), i.e., to show that the middle term M “ η ˚ p X q E r p Y p
X q| F s “
S E r p Y | F s is indeed the conditional expectation of the left of Equation (7), we must verify two conditions: (i) M is F -measurable and (ii) the integrals of Y p Y 1 and M are identical on any event
A in F [Durrett, 2010, page 221].
Condition (i) is immediate, since M is a function of η ˚ p X q and nothing more.
For condition (ii), we do a bit of computation.
Let A “ A S ˆ A T ˆ
A U ˆ A V
ˆ A W be an event in F .
Note that because A is F -measurable, the sets A U and A V must be all of Ω U and Ω V or the empty set.
Suppose for the moment that both are non-empty.
Then, we have
[Equation]
Note that the crucial first and last equalities in which we break and reform the integral over the entire event in terms of its coordinates is possible due to Fubini’s theorem for integrable functions.
This proves the desired equality when A U “ Ω U and A V “ Ω V , and from the preceding calculation we can see that the integrals are both 0 when either A U “ H or A V “ H , and so the desired equality holds.
This establishes the left equality of Equation (7).
Establishing the right hand side of Equation (7) also takes a bit of calculation.
First, we have already verified the measurability condition (i), and so all that remains is to check the integral equality.
Again, let A be an event in F , and assume that A T , A U , and A W are non-empty.
We have
[Equation]
Note that Fubini’s theorem is again used in the first step.
In the event that any of A T , A U , or A W is empty, then the above equation is 0 and equality holds.
Now, we have to show that the random variable M 1 “ ş A T ş A W r p S, T, W q d P W d P T | S is the conditional expectation of p Y with respect to
F .
Measurability is readily apparent, as M 1 is a function of S and no more.
Now, we check the condition that p Y and M 1 have the same integral on an event A in F .
Again assume that A U and A W are non-empty, observing in the calculation to follow that equality holds with the value
if either is empty.
Using Fubini’s theorem and some direct computation, we have ż
[Equation]
This completes the proof that the conditional expectation of p Y is M 1 , and so it proves that the conditional expectation of Y p Y is η ˚ p
X
q E r p Y | F s .
This is the right equality of Equation (7), thus completing the proof.
It follows from Lemma 18 that, if M p C p Y q is maximized by any stochastic classifier, then it is maximized by a classifier p
Y of the form in Eq.
It remains to show that f in Eq.
(6) can be of the form z ÞÑ p 1 t z “ t u ` 1 t z ą t u for some threshold p p, t q P r 0 , 1 s 2 .
Before proving this, we give a simplifying lemma showing that the problem of maximizing a CMM can be equivalently framed as a particular functional optimization problem.
This will allow us to to significantly simplify the notation in the subsequent proofs.
Lemma 19.
Let M be a CMM, and suppose
that M p C p
Y q is maximized (over SC ) by a classifier p
Y of the form
[Equation]
for some f ˚ : r 0 , 1 s Ñ r 0 , 1 s .
Let f be a solution to the optimization problem
[Equation]
Then, the classifier
[Equation]
„ Bernoulli p f p
[Equation]
x qqq
[Equation]
also maximizes M p C p Y 1 q (over SC ).
Proof.
This result follows from the definition (Definition 1) of a CMM.
Specifically, by construction of p Y 1 ,
TP p Y
[Equation]
Y and
[Equation]
Moreover, since the proportions of positive and negative true labels are independent of the chosen classifier (i.e., TP p Y 1 ` FN p Y 1 “ TP p Y ` FN p Y and FP p Y 1 ` TN p Y 1 “ FP p Y ` TN p Y ), we have
[Equation]
where ϵ 1 : “ FP p Y ´
FP p Y 1 P r 0 , FP p Y s and ϵ 2 : “ TP p Y 1 ´ TP p Y P r 0 , FN s .
Thus, by the definition (Definition 1) of a CMM, M p C p
Y 1 q ě M p C p
Y q .
Lemma 19 essentially shows that maximizing any CMM M is equivalent to performing NeymanPearson classification, at some particular false positive level α depending on M (through f ˚ ) and on the distribution of η p X q .
For our purposes, this simplifies the remaining steps in proving Theoremby allowing us to ignore the details of the particular CMM M and regression function η and focus on characterizing solutions to an optimization problem of the form (8) (see, specifically, (9) below).
To characterize solutions to this optimization problem, we will utilize the following two measuretheoretic technical lemmas:
Lemma 20.
Let µ be a measure on r 0 , 1 s with µ pr 0 , 1 sq ą 0 .
Then, there exists z P R such that, for all ϵ ą 0 , µ pr 0 , 1 s X p z
´ ϵ, z qq ą 0 .
Proof.
We prove the contrapositive.
Suppose that, for every z P r 0 , 1 s , there exists ϵ z ą
such that µ pr 0 , 1 s X p z
´ ϵ z , z qq “ 0 .
The family S : “ tr 0 , 1 s X p z ´ ϵ z , z q : z P R u is an open cover of r 0 , 1 s .
Since r 0 , 1 s is compact, there exists a finite sub-cover S 1 Ď S of r 0 , 1 s .
Thus, by countable subaddivity of measures,
[Equation]
Lemma 21.
Let p X , Σ , µ q be a measure space, let E, F P Σ be measurable sets, and let f : X Ñ R be a Σ -measurable function.
If
[Equation]
then there exist measurable sets A Ď E and B Ď F with µ p A q , µ p B q ą 0 , and
[Equation]
Proof.
If ess sup µ f p E q ą ess inf µ f p F q , then there exist a ą b such that ess sup µ f p
E q ą a ą b ą ess inf µ f p F q .
Since ess sup µ f p E q ą a , it follows that P Z p E X t z : f p z q ě a uq ą 0 .
Similarly, since ess inf µ f p F q ă b , it follows that P Z p F X t z : f p z q ď b uq ą 0 .
Hence, letting
A “ E X t z : f p z q ě a u and B “ F X t z : f p z q ď b u , we have
[Equation]
We are now ready for the main remaining step in the proof of Theorem 3, namely characterizing solutions of (a generalization of) the optimization problem (8):
Lemma 22.
Let Z be a r 0 , 1 s -valued random variable, and let c P r 0 , 1 s .
Suppose that the optimization problem
[Equation]
subject to
[Equation]
has a solution.
Then, there is a solution to (9) that is a stochastic threshold function.
Proof.
Suppose that there exists a solution f to (9).
We will construct a stochastic threshold function that solves (9) in two main steps.
First, we will construct a monotone solution to (9).
Second, we will show that this monotone solution is equal to a stochastic threshold function except perhaps on a set of probability 0 with respect to Z .
This stochastic threshold function is therefore a solution to (9).
Construction of Monotone Solution to (9) : Define
[Equation]
where the essential supremum and infimum are taken with respect to the measure P Z of Z , with
the conventions g p z q “ 0 whenever P Z pr 0 , z sq “ 0 and h p
z q “ 1 whenever P Z pp z, 1 sq “ 0 .
We first show that, for all z P r 0 , 1 s , g p z q ď h p z q .
We will then use this to show that g “ f except on a set of
P Z measure 0 (i.e., P Z pt z P r 0 , 1 s : g p z q ‰ f p z quq “ 0 ).
Therefore, both E r Zg p Z qs “ E r Zf p
Z qs and E
rp 1 ´
Z q g p Z qs “ E rp 1 ´
Z q f p Z qs .
Since g : r 0 , 1 s Ñ r 0 , 1 s is clearly monotone non-decreasing, the result follows.
Suppose, for sake of contradiction, that, for some z P r 0 , 1 s , g p
z
q ą h p z q .
By Lemma 21, there exist A Ď r 0 , z s and B Ď p z, 1 s such that inf z P
A f p z q ą sup z P B f p z q and P Z p
A q , P Z p B q ą 0 .
Define z
A : “ E r Z | Z P
A s and z B : “ E r Z | Z P B s , and note that, since A Ď r 0 , z s and B Ď p z, 1 s ,
z A ă z B .
Define,
[Equation]
and define ϕ : r 0 , 1 s Ñ r 0 , 1 s by
[Equation]
otherwise, noting that, by construction of ϵ , ϕ p z q P r 0 , 1 s for all z P r 0 , 1 s .
Then, by construction of ϕ ,
[Equation]
while
[Equation]
since the function z ÞÑ z 1 ´ z is strictly increasing.
This contradicts the assumption that f optimizes (9), implying g ď h .
We now show that g “ f except on a set of P Z measure 0 .
First, note that, if g p z q ‰ f p z q , then g p z q “ ess sup f pr 0 , z sq “ ess sup f pr 0 , z qq , and so g is left-continuous at z .
For any δ ą 0 , define
[Equation]
and
[Equation]
Since
[Equation]
f p z q ´ 1 j * and t z P r 0 , 1 s : g p z q ą f p z qu “ 8 ď j “" z P r 0 , 1 s : g p z
q ą f p z q ` 1 j * , by countable subadditivity, it suffices to show that P Z p A δ q “ P Z p B
δ q “ 0 for all δ ą 0 .
Suppose, for sake of contradiction, that P Z p
A δ q ą 0 .
Applying Lemma 20 to the measure E ÞÑ
P Z p
A δ X E q , there exists z P R such that, for any ϵ ą 0 , P Z p
A δ X p
z ´
ϵ, z qq ą 0 .
Since g is continuous at z , there exists ϵ ą 0 such that g p z ´ ϵ q ě g p z q ´ δ , so that, for all z P A δ X p
z
´
ϵ, z q , f p z
q ą g p z q ` δ .
Then, since P Z p A δ X p z ´
ϵ, z qq ą 0 , we have the contradiction
g p z q ě ess sup f p
A δ X p
z ´
ϵ, z qq ą g p z q .
On the other hand, suppose, for sake of contradiction, that P Z p B δ q ą 0 .
Applying Lemma 20 to the measure E ÞÑ P
Z p B δ X E q
, there exists z P R such that, for any ϵ ą 0 , P Z p B δ X p
z ´
ϵ, z qq ą 0 .
Since g is continuous at z , there exists ϵ ą 0 such that g p z ´ ϵ q ě g p z q ´ δ .
At the same time, since g is non-decreasing, for t P B δ X p z ´ ϵ, z q , f p t q ă g p t q ´ δ ď g p
z
q ´ δ .
Thus, since
P Z p B δ X p
z ´
ϵ, z qq ą 0 , we have h p z
´ ϵ q ă g p z q ´
δ ă g p z
´ ϵ q , contradicting the previously shown fact that g ď h .
To conclude, we have shown that P Z pt z P r 0 , 1 s : g
[Equation]
Construction of a Stochastic Threshold Solution: We now construct a solution to (9) that is equal to a stochastic threshold function (i.e., a function that has the form p 1 t z “ t u ` 1 t z ą t u ) except on a set of P Z -measure 0 .
To show this, it suffices to construct a function f : r 0 , 1 s Ñ r 0 , 1 s such that (a) f is monotone non-decreasing and (b) the set f ´ 1 pp 0 , 1 qq is the union of the singleton t t u and a set of P Z -measure 0 .
From the previous step of this proof, we may assume that we have a solution f to (9) that is monotone non-decreasing.
It suffices therefore to show that A : “ f ´ 1 pp 0 , 1 qq is the union of a singleton and a set of P Z -measure 0 .
Define
[Equation]
and
[Equation]
Then, for all ϵ ą 0 , P Z p A X r 0 , t
´
ϵ sq “ P Z p
A X r t 1 ` ϵ, 1 sq “ 0 .
Hence, if t 0 “ t 1 , then, since
A zt t 0 u “ 8 ď j “
A X pr 0 , t 0 ´ 1 { j s Y r t 1 ` 1 { j, 1 sq by countable subadditivity, P Z p
A zt t 0 uq “ 0 , which implies that A “ t t 0 u Y p
A zt t 0 uq is the union of a singleton and a set of measure 0 .
It suffices therefore to prove that t 0 “ t 1 .
It is easy to see, from the definitions of t 0 and t 1 , that t 0 ď t 1 .
Suppose, for sake of contradiction, that t 0 ă t 1 .
Then, there exists t P p t 0 , t 1 q , and, by definition of t 0 and t 1 , both P Z p A X r 0 , t qq ą 0 and P Z p
A X p t, 1 sq ą 0 .
For any δ ě 0 , define
B δ : “ t z P r 0 , t q : δ ă f p z q ă 1 ´ δ u and
C δ : “ t z P p t, 1 s : δ ă f p z
q ă 1 ´ δ u , so that P Z p B 0 q ą 0 and P Z p C 0 q ą 0 .
By countable subadditivity, there exists δ ą 0 such that
P Z p B δ q ą 0 and P Z p C
δ q ą 0 .
Define ϵ : “ δ ¨ min t P Z p B δ q , P Z p C δ quu ą 0 .
Define g : r 0 , 1 s Ñ R for all z P r 0 , 1 s by g p
z
q “
[Equation] [Equation]
if z P C δ f p z q otherwise .
and note that, by definition of ϵ , B δ , and C δ , g : r 0 , 1 s Ñ r 0 , 1 s .
Then,
E
[Equation]
while
[Equation]
Since B δ Ď r 0 , t q and C δ Ď p t, 1 s , this difference is strictly positive, contradicting the assumption that f optimizes (9).
Combining Lemma 22 with Lemma 19 completes the proof of our main result, Theorem 3.
A.1 Extension to AUROC
For any regression function η , the receiver operating characteristic (ROC) function ROC η : r 0 , 1 s Ñ r 0 , 1 s is
[Equation]
for all x P
[Equation]
i.e., ROC p x q is the maximum true positive probability (over all regression-thresholding classifiers with regression function η ) achievable while keeping the false positive probability below x .
The area under the ROC curve (AUROC) is then given by
[Equation]
[Equation]
While AUROC is not a CMM (as it depends on the entire family of confusion matrices computed at all possible thresholds p p, t q P r 0 , 1 s 2 ), AUROC is widely used to measure performance of classifiers across the classification thresholds.
Here, we show that our Theorem 3 extends naturally from CMMs to AUROC.
We begin by noting that, for any x P r 0 , 1 s , the performance measure TP ¨ 1 t FP ď x u is a CMM.
Therefore, letting η ˚ denote the true regression function, by Theorem 3, there exists a threshold p p, t q P r 0 , 1 s 2 such that the regression-thresholding classifier p Y p,t,η ˚ P argmax p Y P SC TP ¨ 1 t FP ď x u ; i.e., p Y p,t,η ˚ maximizes TP ¨ 1 t FP ď x u over all stochastic classifiers.
By definition of ROC (Eq.
, it follows that, for any x P r 0 , 1 s ,
[Equation]
and, by definition AUROC (Eq.
, it then follows that
[Equation]
To conclude, we have shown that thresholding the true regression function is optimal not only under any CMM but also under AUROC.
A identical argument can be made for other performance measures, such as the area under the precision-recall curve (AUPRC), that aggregate CMMs across multiple classification thresholds.
B Relative Performance Guarantees in terms of the Generalized Bayes Classifier
In this Appendix, we prove Lemmas 5 and 6, as well as their consequence, Corollary 8.
Also, in
Section B.1, we demonstrate, in a few key examples, how to compute the Lipschitz constant used in
Corollary 8.
We begin with the proof of Lemma 5, which, at a given threshold p p, t q , bounds the difference between the confusion matrices of the true regression function η and an estimate η 1 of η .
We restate the result for the reader’s convenience:
Lemma 5.
Let p, t P r 0 , 1 s and let η, η 1 : X Ñ r 0 , 1 s .
Then,
[Equation]
Proof.
For the true negative probability, we have
[Equation]
This type of inequality is standard and follows from the fact that, if t lies between η and η 1 , then the difference of η and t is necessarily less than η and η 1 .
Repeating this calculation for the true positive, false positive, and false negative probabilities gives (12).
Note that, in the presence of degree r Uniform Class Imbalance (see Section 5), one can obtain a tighter error bound r P r| η p X q ´ t | ď } η ´ η 1 } 8 s for the true positive and false negative probabilities because, for all x P X , P r Y “ 1 | X “ x s ď r .
However, the weaker bound (12) simplifies the exposition.
We now turn to proving Lemma 6, which we use to bound the maximum difference between the empirical and true confusion matrices of a regression-thresholding classifier over thresholds p p, t q .
Specifically, we will use this result to bound the difference in confusion matrices between the optimal threshold p p ˚ , t ˚ q and the threshold p p p, p t q selected by maximizing the empirical CMM.
We actually prove a more general version of Lemma 6, for arbitrary classifiers, based on the following definition:
Definition 23 (Stochastic Growth Function) .
Let F be a family of r 0 , 1 s -valued functions on X .
The stochastic growth function Π F : N Ñ N , defined by
[Equation]
all n P N
[Equation]
is the maximum number of distinct classifications of n points x 1 , ..., x n by a stochastic classifier p Y with p x ÞÑ E r p
Y p x qsq P F and randomness given by z 1 , ..., z n .
Definition 23 generalizes the growth function [Mohri et al., 2018], a classical measure of the complexity of a hypothesis class originally due to Vapnik and Chervonenkis [2015], to non-deterministic classifiers.
Importantly for our purposes, one can easily bound the stochastic growth function of regression-thresholding classifiers:
Example 24 (Stochastic Growth Function of Regression-Thresholding Classifiers) .
Suppose
F “ t f : X Ñ r 0 , 1 s| for some p, t P r 0 , 1 s , f p x q “ p ¨ 1 t η p x q “ t u ` 1 t η p x q ą t u for all x P X u , so that t p Y f,η : f P F u is the class of regression-thresholding classifiers.
Any set of points p x 1 , z 1 q , ..., p x n , z n q , can be sorted in increasing order by η p x q ’s, breaking ties in decreasing order by z ’s. Having sorted the points in this way, t f p x q ą z u “ 0 for the first j points and t f p x q ą z u “for the remaining n ´ j points, for some j P r n s Y t 0 u .
Thus, Π F p n q “ n ` 1 .
We will now prove the following result, from which, together with Example 24, Lemma 6 follows immediately:
Lemma 6 (Generalized Version) .
Let F be a family of r 0 , 1 s -valued functions on X .
Then, with probability at least 1 ´ δ ,
[Equation]
Before proving Lemma 6, we note a standard symmetrization lemma, which allows us to replace the expectation of x TN p Y p,t,η with its value on an independent, identically distributed “ghost sample”.
Lemma 25 (Symmetrization; Lemma 2 of Bousquet et al.
Let X and X 1 be independent realizations of a random variable with respect to which F is a family of integrable functions.
Then, for any ϵ ą 0 ,
[Equation]
We now use this lemma to prove Lemma 6.
Proof.
To facilitate analyzing the stochastic aspect of the classifier p
Y f,η , let Z 1 , ..., Z n IID „
Uniform pr 0 , 1 sq , such that p Y f,η p
X
i q “ 1 t Z i ă f p η
pp X
i qqu .
Now suppose that we have a ghost sample p X 1 1 , Y 1 1 , Z 1 1 q , ..., p X 1 n , Y 1 n , Z 1 n q .
Let x TN 1 p Y f,η denote the empirical true negative probability computed on this ghost sample, and let x
TN p i q p Y f,η denote the empirical true negative probability computed on
[Equation]
(i.e., replacing only the i th sample with its ghost).
By the Symmetrization Lemma,
[Equation]
where the second inequality is a union bound over the Π F p 2 n q distinct classifications of 2 n points that can be assigned by p Y f,η with f P F , and the last inequality is from the fact that x TN p Y f,η and x TN 1 p Y f,η are identically distributed and the algebraic fact that, if a ´ b ą ϵ , then either a ´ c ą ϵ { 2 or b ´ c ą ϵ { 2 .
For any particular f P F , by McDiarmid’s inequality [McDiarmid, 1998],
[Equation]
since, for any i P r n s ,
[Equation]
Plugging Inequality (14) into Inequality (13) gives
[Equation]
Repeating this argument with ´ x TN instead of x TN, as well as with x TP, x FN, x FP and their negatives, and taking a union bound over these 8 cases, gives the desired result.
Finally, we will use these two lemmas, together with the margin and Lipschitz assumptions, to prove
Corollary 8, which bounds the sub-optimality of the trained classifier, relative to
the generalized
Bayes classifier, in terms of the desired CMM.
Corollary 8.
Let η : X Ñ r 0 , 1 s denote the true regression function, and let p η : X Ñ r 0 , 1 s denote any empirical regressor.
Let
[Equation]
and
[Equation]
denote the empirically selected and true optimal thresholds, respectively.
Suppose that M is Lipschitz continuous with constant L M with respect to the uniform ( L 8 ) metric on C .
Finally, suppose that
P X and η satisfies a p C, β q -margin condition around t ˚ .
Then, with probability at least 1 ´ δ ,
M
[Equation]
Proof.
First, note that
[Equation]
since, by definition of p p p, p t q ,
[Equation]
this term sits between the second and third lines above.
By the Lipschitz assumption,
[Equation]
Corollary 8 follows by applying Lemma 5 and the p C,
β q -margin condition to (15) and applying
Lemma 6 to both terms (16) and (17).
B.1 Lipschitz constants for some common CMMs
Corollary 8 assumed that the CMM M was Lipschitz continuous with respect to the sup -norm on confusion matrices.
In this section, we show how to compute appropriate Lipschitz constants for several simple example CMMs.
We begin with a simple example:
Example 26 (Weighted Accuracy) .
For a fixed w P p 0 , 1 q , the w -weighted accuracy is given by
M p C q “ p 1 ´ w q TP ` w TN.
In this case, M clearly has Lipschitz constant L M “ max t w, 1 ´ w u .
For the remainder of this section (only), we will use P : “ E r Y s to denote the positive probability of the true labels and p P : “ 1 n ř ni “ 1 Y i to denote the empirical positive probability of the true labels.
Many CMMs of interest, such as Recall and F β scores, are not Lipschitz continuous over all of C .
Fortunately, inspecting the proof of Corollary 8, it suffices for the CMM M to be Lipschitz continuous on the line segments between three specific pairs of confusion matrices, given in Eqs.
(15), (16), and (17).
Deriving the appropriate Lipschitz constants is a bit more complex, and we demonstrate here how to derive them for the specific CMMs of Recall and F β scores.
Of the six confusion matrices in Eqs.
(15), (16), and (17), four are true confusion matrices, while the other two are empirical.
The four true confusion matrices have the same positive probability
TP ` FN “ P , which is a function of the true distribution of labels.
The two empirical confusion matrices have the positive probability x TP ` x FN “ p P , which is a function of the data.
By a multiplicative Chernoff bound, with probability at least 1 ´ e ´ nP { 8 , p P ě P { 2 .
Thus, with high probability, it suffices for the CMM M to be Lipschitz continuous over confusion matrices with positive probability at least P { 2 .
For Recall and F β scores, this gives the following Lipschitz constants:
Example 27 (Recall) .
Recall is given by M p C q “
TP TP ` FN “ TP P .
Thus, M is Lipschitz continuous with constant L M “ 2 P over the confusion matrices in Eqs.
(15), (16), and (17).
Example 28 ( F β Score) .
For β P p 0 , 8q , the F β score is given by
[Equation]
Hence,
[Equation]
while, since TP ď P ,
[Equation]
Hence, M is Lipschitz continuous with constant 2 p 1 ` β 2 q P max ␣ β ´ 2 , β ´ 4 ( over the confusion matrices in Eqs.
(15), (16), and (17).
As Examples 27 and 28 demonstrate, the Lipschitz constants of some CMMs can become large when the proportion P is positive samples is small.
In particular, when P P O ˆb log nn ˙ , the — L M b log p n { δ q n term of Corollary 8 fails to vanish as n Ñ 8 .
We believe that some loss of convergence rate is inevitable if P Ñ 0 as n Ñ 8 , due to the inherent instability of such metrics, but further work is needed to understand if the rates given by Corollary 8 are optimal under these metrics.
See also Dembczy´nski et al.
[2017] for detailed discussion of Lipschitz constants of many common
CMMs.
C Bounds on Uniform Error of the Nearest Neighbor Regressor
In this appendix, we prove our upper bound on the uniform risk of the k NN regressor (Theorem 15), as well as the corresponding minimax lower bound (Theorem 17).
C.1 Upper Bounds
Here, we prove Theorem 15, our upper bound on the uniform error of the k -NN regressor, restated below:
Theorem 15.
Under Assumptions 13 and 14, whenever k { n ď p ˚ p ϵ ˚ q d { 2 , for any δ ą 0 , with probability at least 1 ´ N
[Equation]
, we have the uniform error bound
[Equation]
Proof.
For any x P X , let
[Equation]
denote the mean of the true regression function over the k nearest neighbors of x .
By the triangle inequality,
[Equation]
wherein } η ´ r η k } 8 captures bias due to smoothing and } r η k ´ p η } 8 captures variance due to label noise.
We separately show that, with probability at least 1 ´ N
[Equation]
and that, with probability at least 1 ´ δ ,
[Equation]
Bounding the smoothing bias Fix some r ą 0 to be determined, and let t B r p z 1 q , ..., B r p z N p r q qu be a covering of p X , ρ q by N p r q balls of radius r , with centers z 1 , ..., z N p r q P X .
By the lower bound assumption on P X , each P X p B r p z j qq ě p ˚ r d .
Therefore, by a multiplicative
Chernoff bound, with probability at least 1 ´ N p r q e ´ p ˚ nr d { 8 , each B r p z
j q contains at least p ˚ nr d {samples.
In particular, if r ě ´ 2 k p ˚ n ¯ 1 { d , then each B k contains at least k samples, and it follows that, for every x P X , ρ p x, X σ k p x q q ď 2 r .
Thus, by Hölder continuity of η ,
[Equation]
Finally, if kn ď p ˚ 2 p r ˚ q d , then we can let r “
[Equation]
Bounding variance due to label noise Let Σ : “ t σ p x q P r n s k : x P X u denote the set of possible k -nearest neighbor index sets.
One can check from the definition of the shattering coefficient that | Σ | ď S p n q .
For any σ P r n s k , let Z σ : “ ř kj “ 1 Y σ j and let µ σ : “ E r Z σ s .
Note that the conditional random variables Y σ j | X 1 , ..., X n have conditionally independent Bernoulli distributions with means
E r Y σ j | X 1 , ..., X n s “ η p X σ j q and variances E
[Equation]
η p X σ j qq ď r .
Therefore, by Bernstein’s inequality (Eq.
(2.10) of Boucheron et al.
[2013]), for any ϵ ą 0 ,
[Equation]
Moreover, for any x P X , µ σ p x q “ r η k p x q and Z σ p x q { k “ p η p x q .
Hence, by a union bound over σ in Σ ,
[Equation]
Since the right-hand side is independent of X 1 , ..., X n , the unconditional bound
[Equation]
follows.
Plugging in
[Equation]
and simplifying gives the final result.
Recall that there is a small (polylogarithmic in r ) gap between our upper and lower bounds.
We believe that the upper bound may be slightly loose, and that this might be tightened by using a stronger concentration inequality, such as Bennett’s inequality [Bennett, 1962], instead of Bernstein’s inequality in Inequality (19).
Naively applying Theorem 15 results in very slow convergence rates in high dimensions.
For this reason, we close this section with a corollary of Theorem 15, illustrating that the convergence rates provided by Theorem 15 improve if the covariates are assumed to lie on an (unknown) lower dimensional manifold:
Corollary 29 (Implicit Manifold Case) .
Suppose Z is a r 0 , 1 s d -valued random variable with a density lower bounded away from 0 , and suppose that, for some Lipschitz map T : r 0 , 1 s d Ñ R D ,
X “ T p Z q .
Then, N p ϵ q ď p 2 { ϵ q d , and S p n q ď 2 n D ` 1 ` 2 , and so, by Theorem 15, k — n
[Equation]
2 α
[Equation]
d p
[Equation]
α
[Equation]
This shows that, if the D covariates lie implicitly on a d -dimensional manifold, convergence rates depend on d , which may be much smaller than D .
C.2 Lower Bounds
In this section, we prove Theorem 17, our lower bound on the minimax uniform error of estimating a
Hölder continuous regression function.
We use a standard approach based on the following version of Fano’s lemma:
Lemma 30.
(Fano’s Lemma; Simplified Form of Theorem 2.5 of Tsybakov 2009)
Fix a family P of distributions over a sample space X and fix a pseudo-metric ρ : P ˆ P Ñ r 0 , 8s over P .
Suppose there exist P 0 P P and a set T Ď P such that
[Equation]
where D KL : P ˆ P Ñ r 0 , 8s denotes Kullback-Leibler divergence.
Then,
[Equation]
where the first inf is taken over all estimators p P .
Proof.
We now proceed to construct an appropriate P 0 P P and T Ď P .
Let g : r´ 1 , 1 s d Ñ r 0 , 1 s defined by
[Equation]
else denote the standard bump function supported on r´ 1 , 1 s d , scaled to have } g } X , 8 “ 1 .
Since g is infinitely differentiable and compactly supported, it has a finite α -Hölder semi-norm:
[Equation]
where ℓ is any t β u -order multi-index and g ℓ is the corresponding mixed derivative of g .
Define
M : “
[Equation]
ě 1 , since r ě 1 { n .
For each m P r M s d , define g m : X Ñ r 0 , 1 s by
[Equation]
so that t g m : m P r M s d u is a grid of M d bump functions with disjoint supports.
Let ζ 0 ” 14 denote the constant- 14 function on X .
Finally, for each m P r M s d , define ζ m : X Ñ r 0 , 1 s by
[Equation]
Note that, for any m P r M s d ,
[Equation]
so that ζ m satisfies the Hölder smoothness condition.
For any particular η , let P η denote the joint distribution of p X, Y q .
Note that P ζ p x, 1 q “ ζ p x q ě 1 { 4 .
Moreover, one can check that, for all x ě ´ 2 { 3 , ´ log p 1 ` x q ď x 2 ´ x .
Hence, for any x P X ,
P
[Equation]
and, similarly, since P ζ p x, 0 q “ 1 ´ ζ p x q ě 1 { 4 ,
[Equation]
Adding these two terms gives
[Equation]
where the second inequality comes from the definition of ζ m (Eq. 21) and the third inequality comes from the facts that } g } 22 ď 1 and log log x ď 12 log x for all x ą 1 .
Fano’s lemma therefore implies the lower bound inf
[Equation]
where
[Equation]
D Efficient Computation of the Optimal Stochastic Threshold
Although the focus of this paper is on statistical properties of regression-thresholding classifiers
[Equation]
we note that, given an estimate p η of the regression function, the empirically optimal stochastic threshold p p p, p t q , i.e., that which maximizes M p p C p
Y
p
η, p p, p t q , can be efficiently computed.
In this appendix, we describe a simple algorithm for doing so.
The key insight is that, because p p p, p t q is used to threshold the observed empirical class probabilities p η p X 1 q , ..., p η p X n q before computing M , M p p C
p
Y p η,p,t q only needs to be computed at the n values of p η actually observed in the data.
We also note that, while, by Corollary 8, one can safely use the original training dataset to compute p p p, p t q , one can also safely use a much smaller subset of the data, since the rate of convergence in
Lemma 6 is quite fast in n .
For large n , the runtime of Algorithm 1 is dominated by Line 3, which involves lexicographically sorting n pairs.
This can be done in O p n log n q time using standard comparison-based sorting algorithms.
Hence, the overall runtime of Algorithm 1 is O p n log n q .
E Further Experimental Details
Experiments were run using the numpy and scikit-learn packages in Python 3.9, on a machine running Ubuntu 20.04 with an Intel Core i5-9600 CPU and 64 gigabytes of memory.
Each experiment took about 10 minutes to run.
Python code and instructions for reproducing Figures 2b and 2a are available at https://gitlab.tuebingen.mpg.de/shashank/ imbalanced-binary-classification-experiments .
Input: Estimated regression function p η , training covariate samples X 1 , ..., X n , CMM M .
Output: Estimated optimal stochastic threshold p p p, p t q 1 Sample Z 1 , ..., Z n IID „ Uniform pr 0 , 1 sq 2 e 1 , ..., e n Ð p η p X 1 q , ..., p η p X n q 3 p e 1 , Z 1 q , ..., p e n , Z n q Ð LexicographicSort pp e 1 , Z n q , ..., p e n , Z n qq 4 TP Ð 1 n ř ni “ 1 Y i 5 FP Ð 1 ´ TP 6 TN , FN Ð7 p
p p, p t q Ð p 0 , 0 q 8 M max Ð M ˆ„
TN
FP
FN
TP ȷ˙ 9 for i “ 1; i ă“ n ; i ` ` do
TP Ð TP ´ Y
i { n
FP Ð TP ´ p 1 ´ Y i q{ n
TN Ð TN ` p 1 ´ Y i q{ n
FN Ð FN ` Y i { n
M new Ð M ˆ„
TN
FP
FN
TP ȷ˙ if M new ą M max then p p p, p t
q Ð p e i , Z i q
M max Ð M new 18 end 19 return p p p, p t q
F Experiments with Real Data: Case Study in Credit Card Fraud Detection
In this section, we explore theoretical predictions from the main paper in a real dataset, the Kaggle Credit Card Fraud Detection dataset (available at https://www.kaggle.com/datasets/ mlg-ulb/creditcardfraud under an Open Database License (ODbL)), a widely used benchmark dataset for imbalanced classification.
This dataset contains 29 continuous features (computed via PCA from an underlying set of features) for each of 284,807 credit card transactions, of which 492 ( 0 .
172% ) are labeled as fraudulent, and the remaining are assumed to be non-fraudulent.
The supervised learning task is to predict whether a credit card transaction is fraudulent, given its
PCA features.
Due to computational limitations, we down-sampled the negative set (non-fraudulent transactions) by a factor of 0 before conducting our experiments; however, we expect our main observations to hold on the full dataset as well.
We also Z -scored each feature (to have mean 0 and variance 1 ).
The main question we sought to investigate here was whether the theoretical finding, in Theorem 3, that stochastic classification is sometimes necessary in order to obtain optimal prediction performance under general performance metrics, would be visible in real data.
To investigate this, we partitioned the dataset randomly into a training subset ( 60% of samples), a validation subset ( 20% of samples), and a test subset ( 20% of samples).
We fit a k -nearest neighbor regressor (with Euclidean distance as the underlying metric) to the training subset, used the validation subset to select optimal deterministic and generalization thresholds, and then used the test subset to evaluate performance.
We evaluated performance in terms of F 1 score, since it is perhaps the CMM most widely used with imbalanced datasets.
We then repeated this experiment with 100 random train/validation/test splits and report aggregate results over these independent trials.
We generally found that, as predicted by our theoretical results, stochastic thresholding generally outperforms deterministic thresholding by a small but consistent margin.
Figure 3 shows that, for fixed nearest neighbor hyperparameter k “ 4 , this effect is robust across differing degrees of class imbalance, for imbalance ratios ranging from 1 : 1 (perfect balance) to 57 : 1 (the full dataset), where class imbalance here was manipulated by down-sampling the negative class.
Similarly,
[Figure] [Figure]
Figure 4 shows that this effect is robust over different values of the nearest neighbor hyperparameter k P t 2 , 4 , 8 , 16 , 32 , 64 , 128 u .