SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Meshi Bashari
Technion IIT
meshi.b@campus.technion.ac.il
Amir Epstein
Citi Innovation Lab
amir.epstein@citi.com
Yaniv Romano
yromano@technion.ac.il
Matteo Sesia
Department of Data Sciences and Operations
sesia@marshall.usc.edu
Conformal inference provides a general distribution-free method to rigorously calibrate the output of any machine learning algorithm for novelty detection. While this approach has many strengths, it has the limitation of being randomized, in the sense that it may lead to different results when analyzing twice the same data, and this can hinder the interpretation of any findings. We propose to make conformal inferences more stable by leveraging suitable conformal  $e$ -values instead of  $p$ -values to quantify statistical significance. This solution allows the evidence gathered from multiple analyses of the same data to be aggregated effectively while provably controlling the false discovery rate. Further, we show that the proposed method can reduce randomness without much loss of power compared to standard conformal inference, partly thanks to an innovative way of weighting conformal  $e$ -values based on additional side information carefully extracted from the same data. Simulations with synthetic and real data confirm this solution can be effective at eliminating random noise in the inferences obtained with state-of-the-art alternative techniques, sometimes also leading to higher power.
1.1 Background and motivation
A common problem in statistics and machine learning is to determine which samples, among a collection of new observations, were drawn from the same distribution as a reference data set (Wilks, 1963; Riani et al., 2009; Chandola et al., 2009). This task is known as novelty detection, out-of-distribution testing, or testing for outliers, and it arises in numerous applications within science,
engineering, and business, including for example in the context of medical diagnostics (Tarassenko et al., 1995), security monitoring (Zhang et al., 2013), and fraud detection (Ahmed et al., 2016). This paper looks at the problem from a model-free perspective, in the sense that it does not rely on parametric assumptions about the data-generating distributions, which are generally unknown and complex. Instead, we apply powerful machine learning models for one-class (Moya et al., 1993) or binary classification to score the new samples based on how they conform to patterns observed in the reference data, and then we translate such scores into rigorous tests using conformal inference.
Conformal inference (Vladimir et al., 2005; Lei et al., 2013) provides flexible tools for extracting provably valid novelty detection tests from any black-box model. The simplest implementation is based on random sample splitting. This consists of training a classifier on a subset of the reference data, and then ranking the output score for each test point against the corresponding scores evaluated out-of-sample for the hold-out reference data. As the latter do not contain outliers, the aforementioned rank is uniformly distributed under the null hypothesis that the test point is not an outlier (Laxhammar and Falkman, 2015; Smith et al., 2015; Guan and Tibshirani, 2022), as long as some relatively mild exchangeability assumptions hold. In other words, this calibration procedure yields a conformal  $p$ -value that can be utilized to test for outliers while rigorously controlling the probability of making a false discovery—incorrectly labeling an inlier data point as an "outlier". Further, split-conformal inference produces only weakly dependent  $p$ -values for different test points (Bates et al., 2023), allowing exact control of the expected proportion of false discoveries—the false discovery rate (FDR)—with the powerful Benjamini-Hochberg (BH) filter (Benjamini and Hochberg, 1995).
As visualized in Figure 1a, a limitation of split-conformal inference is that it is randomized—its results for a given data set are unpredictable because they depend on how the reference samples are divided between the training and calibration subsets. However, higher stability is desirable in practice, as randomized methods generally tend to be less reliable and more difficult to interpret (Murdoch et al., 2019; Yu and Kumbier, 2020). This paper addresses the problem of making conformal inferences more stable by developing a principled method to powerfully aggregate tests for outliers obtained with repeated splits of the same data set, while retaining provable control of the FDR. This problem is challenging because dependent p-values for the same hypothesis are difficult to aggregate without incurring into a significant loss of power (Vovk and Wang, 2020; Vovk et al., 2022).
(a) Standard conformal.
(b) derandomized conformal.
Figure 1: Demonstration on two-dimensional synthetic data of standard conformal (a) and derandomized conformal (b) inferences for novelty detection. Circles denote true inliers and squares denote outliers. The colors indicate how often each test point is reported as a possible outlier over 100 independent analyses of the same data. By carefully aggregating evidence from 10 distinct analyses based on independent splits of the same data, the proposed derandomized approach discovers the same outliers consistently and is less likely to make random false discoveries.
This paper utilizes carefully constructed conformal  $e$ -values (Vovk and Wang, 2021) instead of  $p$ -values to quantify statistical significance when testing for outliers under FDR control. The advantage of  $e$ -values is that they make it possible to aggregate the results of mutually dependent tests in a relatively simple way, enabling an effective approach to derandomize conformal inferences. Our contribution is to develop a martingale-based method inspired by Ren and Barber (2023) that leverages  $e$ -value ideas efficiently, as different types of  $e$ -values can be constructed but not all would be powerful
in our context due to the discrete nature of the statistical evidence in conformal inference. We further refine this method and boost power by adaptively weighting our conformal e-values based on an estimate of the out-of-sample accuracy of each underlying machine learning model. A preview of the performance of our solution is given by Figure 1b, which shows that our method can achieve power comparable to that of standard conformal inferences while mitigating the algorithmic randomness.
This paper builds upon  $e$ -values (Vovk and Wang, 2021): quantitative measures of statistical evidence, alternative to p-values, that lend themselves well to the derandomization of data-splitting procedures and to FDR control under dependence (Wang and Ramdas, 2022). There exist several generic methods for converting any p-value into an e-value (Vovk and Wang, 2021). While those  $p$ -to-  $e$  calibrators could be applied for our novelty detection problem, their power turns out to be often quite low due to the fact that conformal p-values are discrete and cannot take very small values unless the sample size is extremely large; see the Supplementary Section S5 for more details.
Therefore, we propose a novel construction of (slightly generalized) e-values inspired by the work of Ren and Barber (2023) on the derandomization of the knockoff filter (Barber and Candès, 2015), which focused on a completely different high-dimensional variable selection problem. A different approach for producing e-values in the context of conformal inference can also be found in Ignatiadis et al. (2023), although the latter did not focus on derandomization. Our approach differs from that of Ignatiadis et al. (2023) because we construct e-values simultaneously for the whole test set, aiming to control the FDR, instead of operating one test point at a time. Simulations show that our approach tends to yield higher power, especially if the test data contain many outliers.
Our second novelty consists of developing a principled method for assigning data-driven weights to conformal e-values obtained from different machine learning models, in such a way as to further boost power. This solution re-purposes transductive (Vovk, 2013) conformal inference ideas to leverage information contained in the test data themselves while calibrating the conformal inferences, increasing the power to detect outliers similarly to Marandon et al. (2022) and Liang et al. (2022).
While this paper focuses on derandomizing split-conformal inferences, there exist other distribution-free methods that can provide finite-sample tests for novelty detection, such as full-conformal inference (Vladimir et al., 2005) and cross-validation+ (Barber et al., 2021). Those techniques are more computationally expensive but have the advantage of yielding relatively more stable conformal p-values because they do not rely on a single random data split. However, full-conformal inference and cross-validation+ also produce conformal p-values with more complicated dependencies, which make it difficult to control the FDR without large losses in power (Benjamini and Yekutieli, 2001) or very expensive computations (Fithian and Lei, 2022; Liang et al., 2022).
Finally, prior works studied how to stabilize conformal predictors by calibrating the output of an ensemble of simpler models (Löfström et al., 2013; Beganovic and Smirnov, 2018; Linusson et al., 2020; Kim et al., 2020; Gupta et al., 2022). However, we consider a distinct problem as we focus on derandomizing conformal novelty detection methods while controlling the FDR.
2 Relevant technical background
Consider  $n$  observations,  $X_{i} \in \mathbb{R}^{d}$ , sampled exchangeably (or, for simplicity, independent and identically distributed) from some unknown distribution  $P_{0}$ , for all  $i \in \mathcal{D} = [n] = \{1, \dots, n\}$ . Then, imagine observing a test set of  $n_{\mathrm{test}}$  "unlabeled" samples  $X_{j} \in \mathbb{R}^{d}$ . The problem is to test, for each  $j \in \mathcal{D}_{\mathrm{test}} = [n + n_{\mathrm{test}}] \setminus [n]$ , the null hypothesis that  $X_{j}$  is also an inlier, in the sense that it was randomly sampled from  $P_{0}$  exchangeably with the data in  $\mathcal{D}$ . We refer to a rejection of this null hypothesis as the discovery that  $X_{j}$  is an outlier, and we indicate the set of true inlier test points as  $\mathcal{D}_{\mathrm{test}}^{\mathrm{null}}$ , with  $n_{\mathrm{test}}^{\mathrm{null}} = |\mathcal{D}_{\mathrm{test}}^{\mathrm{null}}|$ . For each  $j \in \mathcal{D}_{\mathrm{test}}$ , define  $R_{j}$  as the binary indicator of whether  $X_{j}$  is labeled by our method as an outlier. Then, the goal is to discover as many true outliers as possible while controlling the FDR, defined as  $\mathrm{FDR} = \mathbb{E}[(\sum_{j \in \mathcal{D}_{\mathrm{test}}^{\mathrm{null}}R_{j}) / \max\{1, \sum_{j \in \mathcal{D}_{\mathrm{test}}R_{j}}\}]$ .
2.2 Review of FDR control with conformal p-values
After randomly partitioning  $\mathcal{D}$  into two disjoint subsets  $\mathcal{D}_{\mathrm{train}}$  and  $\mathcal{D}_{\mathrm{cal}}$ , of cardinality  $n_{\mathrm{train}}$  and  $n_{\mathrm{cal}} = n - n_{\mathrm{train}}$  respectively, the standard approach for computing split-conformal p-values begins by training a one-class classification model on the data indexed by  $\mathcal{D}_{\mathrm{train}}$ . This model is applied out-of-sample to compute conformity scores  $\hat{S}_i$  and  $\hat{S}_j$  for all calibration and test points  $i \in \mathcal{D}_{\mathrm{cal}}$  and  $j \in \mathcal{D}_{\mathrm{test}}$ , with the convention that larger scores suggest evidence of an outlier. Assuming without loss of generality that all scores take distinct values (otherwise, ties can be broken at random by adding a little noise), a conformal p-value  $\hat{u}(X_j)$  for each  $j \in \mathcal{D}_{\mathrm{test}}$  is then calculated by taking the relative rank of  $\hat{S}_j$  among the  $\hat{S}_i$  for all  $i \in \mathcal{D}_{\mathrm{cal}}$ :  $\hat{u}(X_j) = (1 + \sum_{i \in \mathcal{D}_{\mathrm{cal}}} \mathbb{I} \{\hat{S}_j \leq \hat{S}_i\}) / (1 + n_{\mathrm{cal}})$ . If the null hypothesis for  $X_j$  is true,  $\hat{S}_j$  is exchangeable with  $\hat{S}_i$  for all  $i \in \mathcal{D}_{\mathrm{cal}}$ , and  $\hat{u}(X_j)$  is uniformly distributed on  $\{1 / (1 + n_{\mathrm{cal}}), 2 / (1 + n_{\mathrm{cal}}), \ldots, 1\}$ . Since this distribution is stochastically larger than the continuous uniform distribution on  $[0, 1]$ , one can say that  $\hat{u}(X_j)$  is a valid conformal p-value. Note however that the p-values  $\hat{u}(X_j)$  and  $\hat{u}(X_{j'})$  for two different test points  $j, j' \in \mathcal{D}_{\mathrm{test}}$  are not independent of one another, even conditional on  $\mathcal{D}_{\mathrm{train}}$ , because they share the same calibration data.
Despite their mutual dependence, conformal p-values can be utilized within the BH filter to simultaneously probe the  $n_{\mathrm{test}}$  hypotheses for all test points while controlling the FDR. A convenient way to explain the BH filter is as follows (Storey, 2002). Imagine rejecting the null hypothesis for all test points  $j$  with  $\hat{u}(X_j) \leq s$ , for some threshold  $s \in [0,1]$ . By monotonicity of  $\hat{u}(X_j)$ , this amounts to rejecting the null hypothesis for all test points  $j$  with  $\hat{S}_j \geq t$ , for some appropriate threshold  $t \in \mathbb{R}$ . An intuitive estimate of the proportion of false discoveries incurred by this rule is:
$$
\widehat {\mathrm {F D P}} (t) = \frac {n _ {\text {t e s t}}}{1 + n _ {\text {c a l}}} \cdot \frac {1 + \sum_ {i \in \mathcal {D} _ {\text {c a l}}} \mathbb {I} \left\{\hat {S} _ {i} \geq t \right\}}{\sum_ {j \in \mathcal {D} _ {\text {t e s t}}} \mathbb {I} \left\{\hat {S} _ {j} \geq t \right\}}. \tag {1}
$$
This can be understood by noting that  $\sum_{j\in \mathcal{D}_{\mathrm{test}}}\mathbb{I}\{S_j^{(k)}\geq t\}$  is the total number of discoveries, while the numerator should behave similarly to the (latent) number of false discoveries in  $\mathcal{D}_{\mathrm{test}}$  due to the exchangeability of  $\hat{S}_i$  and  $\hat{S}_j$  under the null hypothesis. With this notation, it can be shown that the BH filter applied at level  $\alpha \in (0,1)$  computes an adaptive threshold
$$
\hat {t} ^ {\mathrm {B H}} = \min  \left\{t \in \{\hat {S} _ {i} \} _ {i \in \mathcal {D} _ {\mathrm {c a l}} \cup \mathcal {D} _ {\mathrm {t e s t}}}: \widehat {\mathrm {F D P}} (t) \leq \alpha \right\}, \tag {2}
$$
and rejects all null hypotheses  $j$  with  $\hat{S}_j\geq \hat{t}^{\mathrm{BH}}$ ; see Rava et al. (2021) for a derivation of this connection. This procedure was proved by Bates et al. (2023) to control the FDR below  $\alpha$ .
2.3 Review of FDR control with AdaDetect
Recently, Marandon et al. (2022) proposed AdaDetect, a more sophisticated version of the method reviewed in Section 2.2. The main innovation of AdaDetect is that it leverages a binary classification model instead of a one-class classifier. In particular, AdaDetect trains a binary classifier to distinguish the inlier data in  $\mathcal{D}_{\mathrm{train}}$  from the mixture of inliers and outliers contained in the union of  $\mathcal{D}_{\mathrm{cal}}$  and  $\mathcal{D}_{\mathrm{test}}$ . The key idea to achieve FDR control is that the training process should remain invariant to permutations of the calibration and test samples. While the true inlier or outlier nature of the observations in  $\mathcal{D}_{\mathrm{test}}$  is obviously unknown at training time, AdaDetect can still extract some useful information from the test data which would otherwise be ignored by the more traditional split-conformal approach reviewed in Section 2.2. In particular, AdaDetect can leverage the test data to automatically tune any desired model hyper-parameters in order to approximately maximize the number of discoveries. A similar idea also motivates the alternative method of integrative conformal p-values proposed by Liang et al. (2022), although the latter requires the additional assumption that some labeled outlier data are available, and is therefore not discussed in equal detail within this paper.
Despite a more sophisticated use of the available data compared to the split-conformal method reviewed in Section 2.2, AdaDetect still suffers from the same limitation that it must calibrate its inferences based on a single random data subset  $\mathcal{D}_{\mathrm{cal}}$ , and thus its results remain aleatory. For simplicity, Section 3.1 begins by explaining how to derandomize standard split-conformal inferences; then, the proposed method will be easily extended in Section 3.3 to derandomize AdaDetect.
3.1 Derandomizing split-conformal inferences
Consider  $K \geq 1$  repetitions of the split-conformal analysis reviewed in Section 2.2, each starting with an independent split of the same reference data into  $\mathcal{D}_{\mathrm{train}}^{(k)}$  and  $\mathcal{D}_{\mathrm{cal}}^{(k)}$ . For each repetition  $k \in [K]$ , after training the machine learning model on  $\mathcal{D}_{\mathrm{train}}^{(k)}$  and computing conformity scores on  $\mathcal{D}_{\mathrm{cal}}^{(k)}$  and  $\mathcal{D}_{\mathrm{test}}$ , one can estimate the false discovery proportion corresponding to the rejection of all test points with scores above a fixed rejection threshold  $t \in \mathbb{R}$ , similarly to (1), with:
$$
\widehat {\mathbf {F D P}} ^ {(k)} (t) = \frac {n _ {\text {t e s t}}}{n _ {\text {c a l}}} \cdot \frac {\sum_ {i \in \mathcal {D} _ {\text {c a l}} ^ {(k)}} \mathbb {I} \left\{\hat {S} _ {i} ^ {(k)} \geq t \right\}}{\sum_ {j \in \mathcal {D} _ {\text {t e s t}}} \mathbb {I} \left\{\hat {S} _ {j} ^ {(k)} \geq t \right\}}. \tag {3}
$$
Note that the estimate in (3) differs slightly from that in (1) as it lacks the “+1” constant term in the numerator and denominator. While it is possible to include the “+1” terms in (3), this is not needed by our theory and we have observed that it often makes our method unnecessarily conservative. For any fixed  $\alpha_{\mathrm{bh}} \in (0,1)$ , let  $\hat{t}^{(k)}$  be the corresponding BH threshold (2) at the nominal FDR level  $\alpha_{\mathrm{bh}}$ :
$$
\hat {t} ^ {(k)} = \min  \left\{t \in \tilde {\mathcal {D}} _ {\text {c a l - t e s t}} ^ {(k)}: \widehat {\mathrm {F D P}} ^ {(k)} (t) \leq \alpha_ {\mathrm {b h}} \right\}, \tag {4}
$$
where  $\tilde{\mathcal{D}}_{\mathrm{cal - test}}^{(k)} = \{\hat{S}_i^{(k)}\}_{i\in \mathcal{D}_{\mathrm{test}}\cup \mathcal{D}_{\mathrm{cal}}^{(k)}}$ . For each test point  $j\in \mathcal{D}_{\mathrm{test}}$ , define the following rescaled indicator of whether  $\hat{S}_j^{(k)}$  exceeds  $\hat{t}^{(k)}$ :
$$
e _ {j} ^ {(k)} = \left(1 + n _ {\mathrm {c a l}}\right) \cdot \frac {\mathbb {I} \left\{\hat {S} _ {j} ^ {(k)} \geq \hat {t} ^ {(k)} \right\}}{1 + \sum_ {i \in \mathcal {D} _ {\mathrm {c a l}} ^ {(k)}} \mathbb {I} \left\{\hat {S} _ {i} ^ {(k)} \geq \hat {t} ^ {(k)} \right\}}. \tag {5}
$$
Intuitively, this quantifies not only whether the  $j$ -th null hypothesis would be rejected by the BH filter at the nominal FDR level  $\alpha_{\mathrm{bh}}$ , but also how extreme  $\hat{S}_j^{(k)}$  is relative to the calibration scores. In other words, a large  $e_j^{(k)}$  suggests that the test point may be an outlier, where this variable can take any of the following values: 0, 1,  $(1 + n_{\mathrm{cal}}) / n_{\mathrm{cal}}$ ,  $(1 + n_{\mathrm{cal}}) / (n_{\mathrm{cal}} - 1)$ , ...,  $(1 + n_{\mathrm{cal}})$ . This approach, inspired by Ren and Barber (2023), is not the only possible way of constructing e-values to derandomize conformal inferences, as discussed in Supplementary Section S5. However, we will show that it works well in practice and it typically achieves higher power compared to standard p-to-e calibrators (Vovk and Wang, 2021) applied to conformal p-values. This advantage partly derives from the fact that (5) can gather strength from many different test points, and partly from the fact that it is not a proper e-value according to the original definition of Vovk and Wang (2021), in the sense that its expected value may be larger than one even if  $X_j$  is an inlier. Instead, we will show that our e-values satisfy a relaxed average validity property (Ren and Barber, 2023) that is sufficient to guarantee FDR control while allowing more numerous discoveries.
After evaluating (5) for all  $j \in \mathcal{D}_{\mathrm{test}}$  and all  $k \in [K]$ , we aggregate the evidence against the  $j$ -th null hypothesis into a single statistic  $\bar{e}_j$  by taking a weighted average:
$$
\bar {e} _ {j} = \sum_ {k = 1} ^ {K} w ^ {(k)} e _ {j} ^ {(k)}, \qquad \sum_ {k = 1} ^ {K} w ^ {(k)} = 1,
$$
based on some appropriate normalized weights  $w^{(k)}$ . Intuitively, the role of  $w^{(k)}$  is to allow for the possibility that the machine learning models based on different realizations of the training subset may not all be equally powerful at separating inliers from outliers. In the remainder of this section, we will take these weights to be known a-priori for all  $k \in [K]$ , thus representing relevant side information; e.g., in the sense of Genovese et al. (2006) and Ren and Candès (2023). For simplicity, one may think for the time being of trivial uninformative weights  $w^{(k)} = 1 / K$ . Of course, it would be preferable to allow these weights to be data-driven, but such an extension is deferred to Section 3.2 for conciseness.
Having calculated aggregate  $e$ -values  $\bar{e}_j$  with the procedure described above, which is outlined by Algorithm S1 in the Supplementary Material, our method rejects the null hypothesis for all  $j \in \mathcal{D}_{\mathrm{test}}$  whose  $\bar{e}_j$  is greater than an adaptive threshold calculated by applying the eBH filter of Wang and
Ramdas (2022), which is outlined for completeness by Algorithm S2 in the Supplementary Material. We refer to Wang and Ramdas (2022) for a more detailed discussion of the eBH filter. Here, it suffices to recall that the eBH filter computes an adaptive rejection threshold based on the  $n_{\mathrm{test}}$  input e-values and on the desired FDR level  $\alpha \in (0,1)$ . Then, our following result states that the overall procedure is guaranteed to control the FDR below  $\alpha$ , under a relatively mild exchangeability assumption.
Assumption 3.1. The inliers in  $\mathcal{D}$  and the null test points are exchangeable conditional on the non-null test points.
Theorem 3.2. Suppose Assumption 3.1 holds. Then, the  $e$ -values computed by Algorithm S1 satisfy:
$$
\sum_ {j \in \mathcal {D} _ {\text {t e s t}} ^ {\text {n u l l}}} \mathbb {E} \left[ \bar {e} _ {j} \right] \leq n _ {\text {t e s t}}. \tag {6}
$$
The proof of Theorem 3.2 is in the Supplementary Section S2. Combined with Theorem 2 from Ren and Barber (2023), this result implies our method controls the FDR below the desired target level  $\alpha$ .
Corollary 3.3 (Ren and Barber (2023)). The eBH filter of Wang and Ramdas (2022) applied at level  $\alpha \in (0,1)$  to  $e$ -values  $\{\bar{e}_j\}_{j\in \mathcal{D}_{\mathrm{test}}}$ , satisfying (6) guarantees FDR  $\leq \alpha$ .
Remark 3.4. Assumption 3.1 does not require that the inliers are independent of the outliers.
Remark 3.5. Theorem 3.2 holds regardless of the value of the hyper-parameter  $\alpha_{\mathrm{bh}}$  of Algorithm S1, which appears in (4). See Section 3.4 for further details about the choice of  $\alpha_{\mathrm{bh}}$ .
3.2 Leveraging data-driven weights
Our method can be extended to leverage adaptive weights based on the data in  $\mathcal{D}$  and  $\mathcal{D}_{\mathrm{test}}$ , as long as each weight  $w^{(k)}$  is invariant to permutations of the test point with the corresponding calibration samples in  $\mathcal{D}_{\mathrm{cal}}^{(k)}$ . In other words, we only require that these weights be written in the form of
$$
w ^ {(k)} = \omega \left(\tilde {\mathcal {D}} _ {\text {c a l - t e s t}} ^ {(k)}\right). \tag {7}
$$