Conformalized Semi-supervised Random Forest for Classification and Abnormality Detection
Yu** Han† Mingwenchan Xu† Leying Guan
Department of Computer Science, The University of Hong Kong Hong Kong, China Department of IEMS Northwestern University Illinois, USA Department of Biostatistics Yale University New Haven, USA
Abstract
The Random Forests classifier, a widely utilized off-the-shelf classification tool, assumes training and test samples come from the same distribution as other standard classifiers. However, in safety-critical scenarios like medical diagnosis and network attack detection, discrepancies between the training and test sets, including the potential presence of novel outlier samples not appearing during training, can pose significant challenges. To address this problem, we introduce the Conformalized Semi-Supervised Random Forest (CSForest), which couples the conformalization technique Jackknife+aB with semi-supervised tree ensembles to construct a set-valued prediction . Instead of optimizing over the training distribution, CSForest employs unlabeled test samples to enhance accuracy and flag unseen outliers by generating an empty set. Theoretically, we establish CSForest to cover true labels for previously observed inlier classes under arbitrarily label-shift in the test data. We compare CSForest with state-of-the-art methods using synthetic examples and various real-world datasets, under different types of distribution changes in the test domain. Our results highlight CSForest’s effective prediction of inliers and its ability to detect outlier samples unique to the test data. In addition, CSForest shows persistently good performance as the sizes of the training and test sets vary. Codes of CSForest are available at https://github.com/yu**han98/CSForest.
.00footnotetext: †Equal contribution. This work was done at Yale University. Correspondence to: [email protected].
1 INTRODUCTION
A classifier typically generates predictions for a test sample by choosing the class label associated with the highest predicted probability. This approach proves inadequate for addressing the increasing demand for assessing prediction reliability in practical scenarios, such as medical diagnosis (Esteva et al.,, 2017; Kompa et al.,, 2021) and autonomous vehicles (Kalra and Paddock,, 2016; Qayyum et al.,, 2020). One approach for addressing this challenge involves minimizing a combined cost associated with misclassification and rejection, permitting the avoidance of predictions for test samples exhibiting high uncertainty. For example, if the maximum estimated probability for the binary response is low where is the estimated probability of beging in class using the training data, we might choose not to predict a test observation (Chow,, 1970; Herbei and Wegkamp,, 2006; Bartlett and Wegkamp,, 2008). This idea has been implemented across various learning algorithms and expanded to address multi-class classification problems (Cortes et al.,, 2016; Ni et al.,, 2019; Charoenphakdee et al.,, 2021). The set-valued prediction via conformal prediction provides an alternative framework (Vovk et al.,, 2005; Papadopoulos et al.,, 2002; Lei and Wasserman,, 2015; Gammerman et al.,, 2013), in which the classifier generates a set covering all possible labels for a given observation based on the conformal score function that measures the plausibility of label for being , e.g., . For instance, one can form the calibrated set-valued prediction set , with being class-dependent and calculated to ensure a desired coverage of the true label (Vovk et al.,, 2005).
Traditionally, classification uncertainty quantification assumes that the training and test samples are independently and identically distributed (i.i.d.) from the same distribution. In reality, this assumption doesn’t always hold. For instance, in medical applications, the test cohort may include samples representing novel pathologies that bear little similarity to the labeled training set (Lin et al.,, 2005). Similarly, network attackers may create new intrusions to evade existing detection systems (Marchette and Marchette,, 2001). Therefore, it becomes essential to assess uncertainty under distributional changes and flag test samples where predictions should not rely solely on the model trained with the training data.
To address this challenge, we introduce CSForest (Conformalized Semi-Supervised Random Forest), an ensemble tree classifier that leverages both labeled training data and unlabeled test data to form calibrated set-valued prediction and flag outliers. The term “semi-supervision” here refers to the utilization of unlabeled test data. CSForest builds upon recent work on test-data optimized calibrated classification framework(Guan and Tibshirani,, 2022). Guan and Tibshirani, (2022) constructs a calibrated semi-supervised set-valued prediction via sample-splitting where one subset of samples is used for training the model while the remaining part is for calibration. In contrast, CSForest avoids the sample-splitting schema, constructing the random forest tree ensembles and calibrating the prediction using all samples. We summarize our contributions into three main aspects:
-
1.
We present a novel classifier, CSForest, designed for classification with calibrated uncertainty quantification in the presence of distributional shifts between training and test datasets. It employs a novel semi-supervised random forest structure that differentiates between observed training classes and unlabeled test data, and adapts the conformalization technique Jackknife+aB (Kim et al.,, 2020) to handle the case of joint and asymmetric utilization of both training and test samples.
-
2.
We provide a theoretical guarantee for true lable coverage using constructed by CSForest, under arbitrarily shifted test distributions. This theoretically ensures the effectiveness of CSForest under varying degrees of data drift.
-
3.
We conduct extensive experiments on simulated and publicly available datasets under various label shift settings to demonstrate CSForest’s gain over existing state-of-the-art methods.
2 RELATED WORK
Distribution Shift. Regarding distributional changes, both the covariate and label shifts are commonly studied (Schölkopf et al.,, 2012). The former assumes the conditional density to be fixed with , the marginal density of , potentially changing (Shimodaira,, 2000; Bickel et al.,, 2009; Gretton et al.,, 2009; Csurka,, 2017); the latter treats , conditional density of given the label , as fixed, but the prevalence of different labels can vary among the observed training classes (Storkey,, 2009; Lipton et al.,, 2018).
Recently, Guan and Tibshirani, (2022) proposes BCOPS, a test-data optimized calibrated classifier, and the Generalized Label Shift (GLS) model defined in eq. (1), which extends the label shift model to include unseen classes to handle outliers. Suppose that the training data is a mixture of different classes. For class , its mixture proportion is , and feature density is , with satisfying . The generalized label shift model assumes a target distribution accepting both label shift among training classes and the appearance of outlier component(s) and requires only to remain the same for each observed class:
(1) |
where , represents the proportion of samples from class in the target distribution, represents the proportion of outlier samples not from the observed classes, and represents the density for the outlier component. Under the GLS model, BCOPS utilizes both labeled training samples and unlabeled test samples to construct calibrated set-valued prediction. The crucial calibration step of BCOPS relies on sample-splitting, which results in low data-utilization efficiency, especially when training or test samples are limited.
Conformal Prediction. Conformal prediction (also known as conformal inference) (Vovk et al.,, 2005; Papadopoulos et al.,, 2002; Lei and Wasserman,, 2015) aims to create statistically rigorous uncertainty sets/intervals for the predictions from classical machine learning models, aiming to cover the true label with a desired probability in the non-asymptotic regime, without model assumptions on how depends on . Consider as (feature, label) pairs, and a new sample where is unobserved. Based on the previous observations, the conformal prediction creates a prediction set for the new instance and ensure that , where is the allowed miscoverage level. For example, in the classification setting, if , then the probability that contains the true label is no smaller than 90%.
A key step in forming the conformal prediction is the choice of the conformal score function , which is used for evaluating how plausible of observing certain , followed by a calibration of the probability for observing via comparing its score to those from labeled training samples. As some examples for classification problems, Romano et al., (2020) considers as the probability (estimated) of observing labels with estimated conditional probability no worse than that of class , and where is a threshold determined by the empirical distribution . Vovk et al., (2005) and Lei, (2014) consider the conformal score as the conditional probability of having label or density of in class , and construct using a class-specific threshold where is determined by the empirical distribution .
Different conformal prediction schemes have been developed in the literature. During the early times, split conformal prediction is usually adopted where we train the conformal score function using one-fold of the data and perform calibration using the remaining (Vovk et al.,, 2005). In recent years, significant progress has been made in cross-conformal prediction to improve data utilization efficiency. Vovk et al., (2018) proposed splitting data into multiple folds, calculating scores for each fold using score functions learned from the remaining data, and aggregating all scores for calibration. Barber et al., (2021) developed Jacknife+ for regression problems, which combines Jacknife with conformal prediction and constructs the prediction interval as
where is the conformal score function using the mean-prediction function learned from training samples excluding . Although Jacknife+ can only provide a worst-case coverage guarantee at level , the achieved empirical coverage is often well-calibrated. Kim et al., (2020) described Jacknife+aB to mediate the computational burden of Jacknife+, which ensembles and calibrates prediction using repeated Bootstraps rather than retraining the model after excluding each training sample.
3 CONFORMALIZED SEMI-SUPERVISED RANDOM FOREST
Despite the popularity of random forest and its variants, existing work implicitly assumes that training and test samples originate from the same distribution. This reliance makes them unreliable in the presence of distributional changes, which can be particularly problematic in safe-critical applications. Classification uncertainty quantification in this setting is also challenging. To address this issue, we introduce CSForest (Conformalized Semi-Supervised Random Forest), a tree-ensemble classifier that produces set-valued predictions designed to incorporate true labels while minimizing the inclusion of false labels, customized to match a target distribution .
(2) | |||
Specifically, CSForest optimizes for a target distribution as a mixture of the training density and test feature density and set , where . If , and the objective of CSForest coincides with the objective of BCOPS, which optimizes for the expected test cohort classification accuracy. On the other hand, when is large, it has a similar objective as the CRF model and optimizes classification performance on samples generated the same way as the training cohort. When is not excessively large, is a significant contributor to , the constrained optimization objective in eq. (2) encourages for unseen outliers even though we do not explicitly model outliers. In other words, if is unlikely to belong to any of the observed training classes, we prefer to classify it as an outlier.
Proposition 3.1.
Set the conformal score function as . Under the GLS model, the solution to eq. (2) is .
Proposition 3.1 rephrases Proposition 2 from Guan and Tibshirani, (2022), and its proof is provided in Appendix A for completeness. CSForest estimates in Proposition 3.1 using a semi-supervised random forest that utilizes labeled training samples and the unlabeled test cohort, coupled with the Jackknife+aB strategy for correct calibration to ensure coverage guarantee. Specifically, for a test sample and a training sample from class with size , CSForest constructs a conformal score function trained without and to measure how likely a sample is from class . More specifically, CSForest replaces the oracle score in Proposition 3.1 when comparing and and replaces expectation is replaced by an empirical version using corresponding . In other words, let be the training sample size for class , the inclusion criterion in Proposition 3.1 is replaced by its empirical version below:
(3) |
The the estimated prediction set is :
(4) |
Given a user-specified weight , Figure 2 presents a graphical illustration of its model structure and Algorithm 1 delineates the ensemble tree constructions and prediction calibrations for CSForest. In Algorithm 1, we use and to denote the training and test sets, respectively, and to denote samples from the training class . For each class , lines 2-5 construct Bootstrapped random forest tree classifiers to separate the training classes and the test samples. The random forest tree refers to a tree whose split is selected by the best split from randomly selected candidate features, as constructed in the random forest, with as the default split number in the R range package. Line 6 constructs the conformal score function , using only the trees excluding test sample and the training sample . In short, Algorithm 1 can be seen as estimating the oracle conformal score under the target distribution with being not excessively large, by utilizing trees from a weighted random forest classifier.
The estimated conformal score functions are then used to construct the calibrated score, , and the prediction set, , in lines 8-13. It is worth noting that, in line 3, to prevent redundant resampling in Bootstrap, we constrain to be the Bootstrap sample of size drawn from training samples, excluding class . It is worth noting that the probability decreases rapidly as increases.
Remark 3.2.
When is empty, is not defined. In this case, We will exclude training sample when calibrating for test sample . Let be the size of . The probability that is bounded by for decently large and , which decreases fast with .
Theorem 3.3 states that CSForest provides a worst-case coverage guarantee for the true response at the level .
Theorem 3.3.
Suppose the generalized label shift model holds where features from class are i.i.d generated from a distribution . For any fixed integers , the constructed from CSForest satisfies:
(5) | ||||
While the proof relies on the previous arguments used in Jacknife+aB for supervised regression problem Kim et al., (2020). However, new conditioning arguments are needed to estabilish exchangeability due to the paired sampling of both training and test samples. Please find the proof of Theorem 3.3 in Appendix A.
Theorem 3.3 ensures per-class coverage for observed training classes, which means we guarantee true label coverage for inlier classes even in arbitrarily shifted test distributions, e.g.,
for any test distribution satisfying the generalized label shift model assumption. Although the theoretical guarantee for the worst-case coverage is at the level , the empirical coverage using CSForest is usually close to or above the targeted level .
4 EXPERIMENTS
4.1 Synthetic Data
We begin with a simple illustrative 2D synthetic dataset and compare the performance using CSForest and three closely related set-valued conformal classifiers: BCOPS, which is a conformalized semi-supervised classifier that uses half of the samples for training while the other half for calibration (see Section 2); DC (density set classifier)(Cadre,, 2006; Lei,, 2014; Hechtlinger et al.,, 2018; Sadinle et al.,, 2019) and CRF (conformalized random forest), which follow the sample-splitting conformal prediction scheme while using the kernel estimate of the per-class density for and the estimated conditional probability of observing a label via a random forest on the training samples as the conformal score functions, respectively.
Example 1.
Let be the feature. We observe two classes in the training data, but the test data contains outliers labeled with . We generate as noise, with different classes separated by the first two dimensions:
Figure 2(A) shows the first two dimensions of samples generated from the three classes . We generated 200 samples from classes 1 and 2 to form the training set and 200 samples from each of the three classes to form the test set. In Figure 2(B), we evaluated the quality of the set-valued prediction using DC, CRF, BCOPS, and CSForest across 20 independent runs with a targeted miscoverage rate at . All four methods achieve the desired 95% coverage on true labels. However, both CSForest and BCOPS adapted to the test cohort and outperformed CRF and DC significantly in outlier detection. Additionally, compared to BCOPS, CSForest had fewer samples with multiple labels from classes 1 and 2 and exhibited a higher rejection rate for outliers.
4.2 Real-World Data
In this section, our primary objective is to evaluate the effectiveness of CSForest on various real-world datasets, focusing on addressing the following three questions:
-
Q1.
Can CSForest detect outliers efficiently while making accurate predictions for inliers in the presence of outliers but no additional label shift among inliers? (denoted as outliers w/o shift.)
-
Q2.
Under the traditional label shift model without outliers, can CSForest achieve competitive performance compared to alternative classifiers? (denoted as shift w/o outliers.)
-
Q3.
Does CSForest demonstrate stable performance as the training and test sample sizes vary?
Q1 and Q2 capture two extreme settings of the GLS model. We have set at its default value for all experiments in the main paper with . In Appendix E, we include the sensitivity analysis of the crucial parameter and shows CSForest performs well for different values of , with being a reasonable choice to balance performance for both inliers and outliers.
Dataset | Method | outliers w/o shift | shift w/o outliers | ||
Type I Error | Type II Error | Type I Error | Type II Error | ||
MNIST | CSForest | 0.0490.006 | 0.091 0.008 | 0.0480.016 | 0.2910.038 |
BCOPS | 0.0480.004 | 0.2370.019 | 0.0420.007 | 0.5560.040 | |
DC | 0.0490.008 | 0.8900.021 | 0.0460.016 | 0.9680.022 | |
CRF | 0.0480.007 | 0.3380.035 | 0.0460.018 | 0.4280.082 | |
ACRF | 0.0460.006 | 0.4300.003 | 0.0250.011 | 0.8840.012 | |
ACRFshift | 0.0460.006 | 0.4320.009 | 0.0550.013 | 0.8280.015 | |
CIFAR-10 | CSForest | 0.0510.008 | 0.0000.000 | 0.0490.013 | 0.0090.035 |
BCOPS | 0.0490.006 | 0.0010.000 | 0.0420.009 | 0.0290.006 | |
DC | 0.0460.007 | 0.0480.091 | 0.0390.010 | 0.0710.115 | |
CRF | 0.0490.008 | 0.0030.000 | 0.0470.015 | 0.0000.000 | |
ACRF | 0.0030.001 | 0.4020.001 | 0.0400.009 | 0.2210.023 | |
ACRFshift | 0.0030.001 | 0.0690.003 | 0.0460.007 | 0.2300.035 | |
FashionMNIST | CSForest | 0.0500.005 | 0.2660.018 | 0.0380.009 | 0.3110.040 |
BCOPS | 0.0500.007 | 0.3810.020 | 0.0380.009 | 0.3110.040 | |
DC | 0.0510.007 | 0.6660.033 | 0.0380.013 | 0.5840.066 | |
CRF | 0.0510.006 | 0.5140.021 | 0.0380.014 | 0.8040.080 | |
ACRF | 0.0510.006 | 0.5370.013 | 0.0540.009 | 0.8350.020 | |
ACRFshift | 0.0460.005 | 0.4810.019 | 0.0720.021 | 0.8140.039 |
Datasets and Baselines. Our evaluation is conducted on three well-established image benchmarks: MNIST (LeCun and Cortes,, 2010), FashionMNIST (Xiao et al.,, 2017), and CIFAR-10 (Krizhevsky et al.,, 2009). Additionally, we have included tabular data from the Network Intrusion domain and Chest X-ray data from the medical domain in the Appendix D.1 to demonstrate the effectiveness of CSForest in handling diverse datasets. To evaluate CSForest’s performance, we compared it with BCOPS, CRF, DC along with two other approaches based on adaptive classification (Romano et al.,, 2020) and the covariate shift conformal prediction Tibshirani et al., (2019): ACRF (Adaptive classifier via random forest) and ACRFshift (Adaptive classifier via random forest under covariate shift). ACRF is a derandomized version of the existing conformalized adaptive random forest classifier (Romano et al.,, 2020), denoted as ACRFrandom, which aims for adaptive coverage across different feature regions. We will show results using ACRF instead of ACRFrandom in the main paper due to the latter’s tendency to produce overly wide prediction sets, due to the attempt to achieve conditional coverage as indicated in the original paper (Romano et al.,, 2020). ACRFshift combines ACRF with the covariate shift conformal prediction. BCOPS, ACRF and ACRFshift all utilize random forest for constructing set-valued predictions, as a fair comparison to CSForest. More details of these baselines are provided in Appendix B.
Training Details and Evaluations. We set the number of trees for CSForest, and repeat all experiments ten times for performance evaluations. We evaluate the effectiveness of all methods using the type I error, type II error, and the average set length of at . Type I error is the percentage of samples with the true label excluded from their associated set-valued prediction for observed classes. This error measure is directly linked to the coverage guarantee in Theorem 3.3. Type II error is calculated as the percentage of samples with containing labels other than the true labels. The average length under the mixed distribution is the optimization objective under the formulation described by eq. (2).
4.2.1 The Outliers w/o Shift Setting
In this section, the test set contains outlier labels relative to the training set but without any additional label shift. For each data set, we constructed the training set by including a subset of class labels and the test set with all labels, e.g., for the MINIST data, the training set had digit labels 0-5 of equal size and the test set included both digit labels 0-5 of equal size and digit labels 6-9. Details of the data subsampling schemes for Q1 can be found in Appendix C.
Table 1 displays the average type I and type II errors of all methods on the test data at . All methods achieved the the targeted coverage rate at when averaging inlier data. Figure 3(A) presents detailed classification results with different methods on the MNIST dataset. Although ACRF, ACRFshift, and CRF achieved slightly higher accuracy compared to CSForest among inlier digits under no additional label shift, CSForest demonstrated the strongest capability to detect outlier digits 6-9, even compared to BCOPS, with an outlier detection accuracy of approximately 90%. Similar results are observed on other datasets, as detailed in Appendix D.2.
4.2.2 The Shift w/o Outliers Setting
In the previous simulations, although we had outliers, the class ratios among inlier classes were balanced and remained the same for training and test data. To verify whether methods like CSForest, designed to achieve per-class coverage rather than marginal coverage, still maintain robustness when handling label shifts among inlier classes, we examine the predictive performance of all methods under the traditional label shift setting in the absence of outliers. For example, for the MNIST data set, the training and test sets contain digit labels 0-5 but with different class proportions. Details of the data subsampling and label shift schemes for Q2 can be found in Appendix C.
The achieved type I and type II errors using different methods in this standard label shift simulation can be found in Table 1. We observed that all methods achieved the desired coverage () with ACRFshift exhibiting high variability. However, CSForest is the only method that achieved consistently low type II errors: CRF has a type II error 10% and 50% more than CSForest on MNIST and FashionMNIST, respectively; BCOPS has a type II error 25% more than CSForest on MNIST; ACRF and ACRFshift both have type II errors more than two folds than those from CSForest on all three data sets. Figure 3(B) presents a detailed view of the prediction results for each class on the MNIST dataset. CSForest contains a higher proportion of samples with only the correct labels in almost every class compared to the baseline models, which underscores the high-quality prediction sets generated by CSForest under Q2, consistent with the lower type II error reported in Table 1. Detailed results on other datasets can be found in Appendix D.2.
4.2.3 Comparisons with Varying Sample Sizes
We conducted a comparison of different methods under varying sample size settings. Specifically, we varied the number of training and test samples per class from 50 to 200. Figure 4 presents the type II errors for inliers and outliers across all models on the MNIST dataset. In Figure 4, it is evident that as training sample size increases, the type II error (inliers) decreases for all methods, while BCOPS and CSForest also benefit from increased test sample sizes. CSForest closely matches the CRF, the best-performing classifier in the inlier classification, for predicting inlier labels as we vary the training/test sample sizes from 50 to 200. CSForest and BCOPs outperformed other methods by a large margin for varying sample sizes for outlier detection, with CSForest significantly improving over BCOPS due to the enhanced data utilization efficiency. Of note, the ability for outlier detection (higher type II error for outliers) ACRFshift deteriorated as sample size increased. This surprising phenomenon is attributed to ACRFshift’s decision rule for outliers, which strongly depends on the sample weights under the covariate shift model, denoted as . A sample is claimed an outlier is very large, and tends to increase with increased training sample sizes (Appendix B). Results on other datasets are consistent with those on MNIST (Appendix D.2).
5 DISCUSSION
We propose CSForest, which aims to construct a calibrated and narrow set-valued prediction set under distributional changes, as a powerful ensemble classifier for robust inlier classification and outlier detection. We theoretically justified its robustness for covering the true class label and confirmed its ability to construct high-quality prediction sets compared to alternative methods via extensive experiments.
Future Work. An interesting question is how much guidance from test samples is needed for effective outlier detection. Can CSForest still utilize the limited test samples for efficient outlier detection? As an exploratory experiment, we consider a challenging MNIST example, where we have 200 samples per class for labels 0-5 in the training set but only five samples per class for labels 0-9 in the test set. Figure 5 shows CSForest achieves an average type II error of approximately 42% for inliers and 60% for outliers, whereas DC exhibits an average type II error of as high as 95%. This highlights the benefits of utilizing a small test set in CSForest and suggesting the potential of extending the framework of CSForest to settings with extremely limited or even single test samples for future exploration.
Additionally, the GLS model assumes that the distribution of remains unchanged, which could be violated in practice. When both the distribution of and the distribution of are allowed to change, the problem becomes much more challenging and less well-defined. One interesting future direction is to relax GLS model and assume bounded small changes in , leading to the investigation of CSForest under an adversarial setting that allows adversarial yet small perturbations in during test time.
Acknowledgements
This work was supported by NSF award DMS2310836.
References
- Barber et al., (2021) Barber, R. F., Candes, E. J., Ramdas, A., and Tibshirani, R. J. (2021). Predictive inference with the jackknife+. The Annals of Statistics, 49(1):486–507.
- Bartlett and Wegkamp, (2008) Bartlett, P. L. and Wegkamp, M. H. (2008). Classification with a reject option using a hinge loss. Journal of Machine Learning Research, 9(8).
- Bickel et al., (2009) Bickel, S., Brückner, M., and Scheffer, T. (2009). Discriminative learning under covariate shift. Journal of Machine Learning Research, 10(9).
- Cadre, (2006) Cadre, B. (2006). Kernel estimation of density level sets. Journal of multivariate analysis, 97(4):999–1023.
- Charoenphakdee et al., (2021) Charoenphakdee, N., Cui, Z., Zhang, Y., and Sugiyama, M. (2021). Classification with rejection based on cost-sensitive classification. In International Conference on Machine Learning, pages 1507–1517. PMLR.
- Chow, (1970) Chow, C. (1970). On optimum recognition error and reject tradeoff. IEEE Transactions on information theory, 16(1):41–46.
- Cortes et al., (2016) Cortes, C., DeSalvo, G., and Mohri, M. (2016). Boosting with abstention. Advances in Neural Information Processing Systems, 29.
- Csurka, (2017) Csurka, G. (2017). Domain adaptation for visual applications: A comprehensive survey. arXiv preprint arXiv:1702.05374.
- Esteva et al., (2017) Esteva, A., Kuprel, B., Novoa, R. A., Ko, J., Swetter, S. M., Blau, H. M., and Thrun, S. (2017). Dermatologist-level classification of skin cancer with deep neural networks. nature, 542(7639):115–118.
- Gammerman et al., (2013) Gammerman, A., Vovk, V., and Vapnik, V. (2013). Learning by transduction. arXiv preprint arXiv:1301.7375.
- Gretton et al., (2009) Gretton, A., Smola, A., Huang, J., Schmittfull, M., Borgwardt, K., and Schölkopf, B. (2009). Covariate shift by kernel mean matching. Dataset shift in machine learning, 3(4):5.
- Guan and Tibshirani, (2022) Guan, L. and Tibshirani, R. (2022). Prediction and outlier detection in classification problems. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 84(2):524–546.
- Hechtlinger et al., (2018) Hechtlinger, Y., Póczos, B., and Wasserman, L. (2018). Cautious deep learning. arXiv preprint arXiv:1805.09460.
- Herbei and Wegkamp, (2006) Herbei, R. and Wegkamp, M. H. (2006). Classification with reject option. The Canadian Journal of Statistics/La Revue Canadienne de Statistique, pages 709–721.
- Kalra and Paddock, (2016) Kalra, N. and Paddock, S. M. (2016). Driving to safety: How many miles of driving would it take to demonstrate autonomous vehicle reliability? Transportation Research Part A: Policy and Practice, 94:182–193.
- Kim et al., (2020) Kim, B., Xu, C., and Barber, R. (2020). Predictive inference is free with the jackknife+-after-bootstrap. Advances in Neural Information Processing Systems, 33:4138–4149.
- Kompa et al., (2021) Kompa, B., Snoek, J., and Beam, A. L. (2021). Second opinion needed: communicating uncertainty in medical machine learning. NPJ Digital Medicine, 4(1):1–6.
- Krizhevsky et al., (2009) Krizhevsky, A., Hinton, G., et al. (2009). Learning multiple layers of features from tiny images.
- LeCun and Cortes, (2010) LeCun, Y. and Cortes, C. (2010). MNIST handwritten digit database.
- Lei, (2014) Lei, J. (2014). Classification with confidence. Biometrika, 101(4):755–769.
- Lei and Wasserman, (2015) Lei, J. and Wasserman, L. (2015). Distribution-free prediction bands for nonparametric regression. Quality control and applied statistics, 60(1):109–110.
- Lin et al., (2005) Lin, J., Keogh, E., Fu, A., and Van Herle, H. (2005). Approximations to magic: Finding unusual medical time series. In 18th IEEE Symposium on Computer-Based Medical Systems (CBMS’05), pages 329–334. IEEE.
- Lipton et al., (2018) Lipton, Z., Wang, Y.-X., and Smola, A. (2018). Detecting and correcting for label shift with black box predictors. In International conference on machine learning, pages 3122–3130. PMLR.
- Marchette and Marchette, (2001) Marchette, D. J. and Marchette, D. (2001). Computer intrusion detection and network monitoring: a statistical viewpoint. Springer.
- Neyman and Pearson, (1933) Neyman, J. and Pearson, E. S. (1933). Ix. on the problem of the most efficient tests of statistical hypotheses. Philosophical Transactions of the Royal Society of London. Series A, Containing Papers of a Mathematical or Physical Character, 231(694-706):289–337.
- Ni et al., (2019) Ni, C., Charoenphakdee, N., Honda, J., and Sugiyama, M. (2019). On the calibration of multiclass classification with rejection. Advances in Neural Information Processing Systems, 32.
- Papadopoulos et al., (2002) Papadopoulos, H., Proedrou, K., Vovk, V., and Gammerman, A. (2002). Inductive confidence machines for regression. In Machine Learning: ECML 2002: 13th European Conference on Machine Learning Helsinki, Finland, August 19–23, 2002 Proceedings 13, pages 345–356. Springer.
- Qayyum et al., (2020) Qayyum, A., Usama, M., Qadir, J., and Al-Fuqaha, A. (2020). Securing connected & autonomous vehicles: Challenges posed by adversarial machine learning and the way forward. IEEE Communications Surveys & Tutorials, 22(2):998–1026.
- Romano et al., (2020) Romano, Y., Sesia, M., and Candes, E. (2020). Classification with valid and adaptive coverage. Advances in Neural Information Processing Systems, 33:3581–3591.
- Sadinle et al., (2019) Sadinle, M., Lei, J., and Wasserman, L. (2019). Least ambiguous set-valued classifiers with bounded error levels. Journal of the American Statistical Association, 114(525):223–234.
- Schölkopf et al., (2012) Schölkopf, B., Janzing, D., Peters, J., Sgouritsa, E., Zhang, K., and Mooij, J. (2012). On causal and anticausal learning. arXiv preprint arXiv:1206.6471.
- Shimodaira, (2000) Shimodaira, H. (2000). Improving predictive inference under covariate shift by weighting the log-likelihood function. Journal of statistical planning and inference, 90(2):227–244.
- Storkey, (2009) Storkey, A. (2009). When training and test sets are different: characterizing learning transfer. Dataset shift in machine learning, 30:3–28.
- Tibshirani et al., (2019) Tibshirani, R. J., Foygel Barber, R., Candes, E., and Ramdas, A. (2019). Conformal prediction under covariate shift. Advances in neural information processing systems, 32.
- Vovk et al., (2005) Vovk, V., Gammerman, A., and Shafer, G. (2005). Algorithmic learning in a random world. Springer Science & Business Media.
- Vovk et al., (2018) Vovk, V., Nouretdinov, I., Manokhin, V., and Gammerman, A. (2018). Cross-conformal predictive distributions. In Conformal and Probabilistic Prediction and Applications, pages 37–51. PMLR.
- Xiao et al., (2017) Xiao, H., Rasul, K., and Vollgraf, R. (2017). Fashion-mnist: a novel image dataset for benchmarking machine learning algorithms. arXiv preprint arXiv:1708.07747.
Checklist
-
1.
For all models and algorithms presented, check if you include:
-
(a)
A clear description of the mathematical setting, assumptions, algorithm, and/or model. [Yes/No/Not Applicable] Yes
-
(b)
An analysis of the properties and complexity (time, space, sample size) of any algorithm. [Yes/No/Not Applicable] Yes
-
(c)
(Optional) Anonymized source code, with specification of all dependencies, including external libraries. [Yes/No/Not Applicable] Not Applicable
-
(a)
-
2.
For any theoretical claim, check if you include:
-
(a)
Statements of the full set of assumptions of all theoretical results. [Yes/No/Not Applicable] Yes
-
(b)
Complete proofs of all theoretical results. [Yes/No/Not Applicable] Yes
-
(c)
Clear explanations of any assumptions. [Yes/No/Not Applicable] Yes
-
(a)
-
3.
For all figures and tables that present empirical results, check if you include:
-
(a)
The code, data, and instructions needed to reproduce the main experimental results (either in the supplemental material or as a URL). [Yes/No/Not Applicable] Yes
-
(b)
All the training details (e.g., data splits, hyperparameters, how they were chosen). [Yes/No/Not Applicable] Yes
-
(c)
A clear definition of the specific measure or statistics and error bars (e.g., with respect to the random seed after running experiments multiple times). [Yes/No/Not Applicable] Yes
-
(d)
A description of the computing infrastructure used. (e.g., type of GPUs, internal cluster, or cloud provider). [Yes/No/Not Applicable] Not Applicable
-
(a)
-
4.
If you are using existing assets (e.g., code, data, models) or curating/releasing new assets, check if you include:
-
(a)
Citations of the creator If your work uses existing assets. [Yes/No/Not Applicable] Yes
-
(b)
The license information of the assets, if applicable. [Yes/No/Not Applicable] Not Applicable
-
(c)
New assets either in the supplemental material or as a URL, if applicable. [Yes/No/Not Applicable] Not Applicable
-
(d)
Information about consent from data providers/curators. [Yes/No/Not Applicable] Not Applicable
-
(e)
Discussion of sensible content if applicable, e.g., personally identifiable information or offensive content. [Yes/No/Not Applicable] Not Applicable
-
(a)
-
5.
If you used crowdsourcing or conducted research with human subjects, check if you include:
-
(a)
The full text of instructions given to participants and screenshots. [Yes/No/Not Applicable] Not Applicable
-
(b)
Descriptions of potential participant risks, with links to Institutional Review Board (IRB) approvals if applicable. [Yes/No/Not Applicable] Not Applicable
-
(c)
The estimated hourly wage paid to participants and the total amount spent on participant compensation. [Yes/No/Not Applicable] Not Applicable
-
(a)
Appendix A PROOFS
A.1 Proof of Proposition 3.1
For the completeness, we provide a reproduction of the proof presented in Guan and Tibshirani, (2022),
Proof.
We first decompose the problem in eq. (2) into independent problems for different classes, referred to as the problem :
(6) | |||
(7) |
Let be the solution to problem , then the solution to problem eq. (2) is .
We then define is the lower percentile of a real-valued function under distribution , i.e.,
(8) |
Following Guan and Tibshirani, (2022), we regard the problem as a hypothesis testing problem where the null hypothesis is and the alternative is . The optimal solution of is which is actually the decision region of above hypothesis with the most powerful level . Therefore, by Neyman–Pearson Lemma (Neyman and Pearson,, 1933), we can construct the likelihood ratio statistic and have the solution where the is the conformal score function of class and is the distribution of from class . Hence, the solution to eq. ((2) is .
∎
A.2 Proof of Theorem 3.3
Proof.
Here, we prove eq. (5) for any given class and the test sample . The original procedure for determining whether we should assign class to sample can also be described as following. First, generate two events, and :
-
1.
Event : Training samples other than class and bootstrap copies for .
-
2.
Event : Test samples other than and bootstrap copies for .
Let for represent bootstrap copies of training class samples. We conduct our conformalized classification using only copies with for , where . The comparison between from class and the test sample is performed by aggregating prediction functions using runs with and excluding both and : .
We will now condition on and , and define . The function can be rewritten as . A key observation is that this can be equivalently expressed as first sampling and constructing the ensemble prediction function comparing and : . We have also dropped the superscript since this dependence disappears after conditioning and restricting ourselves to .
Interestingly, under this new equivalent characterization, sampling followed by bootstrap copies of the class samples is equivalent to drawing bootstrap copies of the samples, which include samples from training class and the test sample , and then kee** only those bootstrap samples where is not included. A similar equivalence was first noted by Kim et al., (2020) and utilized in the Jacknife+aB procedure for traditional supervised regression.
In summary, the decision rule in CSForest for whether to include label in can be equivalently expressed with the following procedure after conditioning on and :
-
1.
Conduct bootstrap resamplings of the samples. Denote these samples as (representing class training samples) and as the test sample . Let be the index of samples in the bootstrap.
-
2.
For each bootstrap, construct a random forest tree separates from other samples (conditioned on).
-
3.
For each pair with , construct and include label if and only if
Note that is the same as .
Define for all . It is obvious that for all . Define as the sum of the row from the comparison matrix A. Then,
Hence, eq. (5) from Theorem 3.3 is equivalent to (9) below:
(9) |
We now proceed to prove (9), which consists of two steps (1) are exchangeable with each other for when , and (2) the strange set satisfies . Combining these two steps, we immediately have
At this stage, proofs to above two steps (1) and (2) become identical to that used in the proofs to Theorem 1 in Barber et al., (2021) or Theorem 1 in Kim et al., (2020).
∎
Appendix B MORE DETAILS ON BASELINES
In this section, we provide more details about the baseline models. We first introduce several existing methods for constructing set-valued predictions , including BCOPS, CRF, DC, and ACRFrandom.
B.1 BCOPS, CRF, DC and ACRFrandom
-
•
BCOPS (Balanced Conformalized Optimal Prediction Sets) (Guan and Tibshirani,, 2022) is a semi-supervised classifier that utilizes half of the training data to train a classifier, separating observed classes from unlabeled test samples. The remaining half of the training samples is used for calibration through conformal prediction and constructing a set-valued prediction set. In contrast, BCOPS focuses on optimizing model performance on the test set, setting , which represents the marginal density for the test data. It constructs calibrated set-valued predictions by combining empirically estimated with the sample-splitting conformal prediction method(Vovk et al.,, 2005). While BCOPS excels in abnormality detection, outperforming non-test-cohort-adaptive methods, it relies on having a large set of test data, and the sample-splitting scheme results in lower data utilization efficiency(Guan and Tibshirani,, 2022).
-
•
CRF (Comformalized Random Forest)(Vovk et al.,, 2005) constructs the set-valued prediction by including training labels achieving high estimated probability from the random forest classifier, with the cut-offs chosen based on sample-splitting conformal prediction.
-
•
DC (Density-set Classifier)(Hechtlinger et al.,, 2018) constructs the set-valued prediction similarly to CRF, except for replacing the estimated probability by an estimation of the density function for class using the training data.
-
•
ACRFrandom: We refer to the adaptive-coverage classification approach using random forest proposed in Romano et al., (2020) as ACRFrandom (Adaptive-coverage CRF with randomization) where the randomization is introduced via an additional uniform random variable for tie-breaking. ACRFrandom constructs the prediction set by including labels with large estimated probabilities such that the total probability is greater than the upper-level quantile of the empirical distribution of where is the calibration set in sample-splitting conformal prediction and is the sum of estimated probabilities for all labels proceeding that for the true label.
B.2 ACRF and ACRFrandom
We further introduce the baseline ACRFrandom and its de-randomized version ACRF.
ACRFrandom
In the original proposal of Romano et al., (2020), the authors assume that training and test data to have the same distribution. ACRFrandom defines a function with input , , the conditional probability , and the threshold . Define
(10) |
where
(11) |
(12) |
and is the largest conditional probability.
Further, ACRFrandom defines the generalized inverse quantile conformity score function ,
(13) |
And the empirical distribution is
(14) |
where is constructed at the minimum for the calibration sample such that is included in and denotes a point mass at . The final prediction set is constructed as , where is the upper level quantile of the empirical distribution .
ACRF
We consider a derandomized version of ACRF without the uniform variable in our experiment. For ACRF, we define
(15) |
where
(16) |
We can similarly define a score function ,
(17) |
and construct as the the minimum for the calibration sample such that is included in . Same as in ACRFrandom, ACRF constructs as , where is the upper level quantile of the empirical distribution . Algorithm 2 shows the details of ACRF.
B.3 ACRFshift
Finally, we introduce ACRFshift, another baseline that explicitly accounts for distributional changes under covariate shift model. ACRFshift combines the covariate shift comformal prediction (Tibshirani et al.,, 2019) with ACRF. This has not been discussed in previous work, so we give details about how this is done in our paper. We split also the test samples into two sets , . Suppose that we now construct the prediction set for test samples in .
Instead of finding with eq. (17) and (14), we consider the following weighted calibration. The weighted function is and is the conditional probability of being generated from the test data ( means from the test data, and represent from the training data), learned from the classifier separating the test data from the training data . Instead of consider as the level quantile of the empirical distribution , for any , we consider the level quantile of the weighted distribution below:
Similarly, whether to include the random variable in ACRF will result in two versions: ACRFshiftrandom and ACRFshift.
Unlike CSForest, BCOPS, and even CRF, which naturally considers samples with as the ones not close to inlier classes, and thus, outliers, ACRF and ACRFshift both consider the conditional probability of and do not have such a feature encoded in their constructions. Hence, we adopt the rule where we reject a sample when is very large compared to others with . (Recall that without covariate shift.)
B.4 Randomized ACRF/ACRFshift vs. derandomized ACRF/ACRFshift
In this section, we further demonstrate the difference between the randomized version and derandomized version to support our claim that removing the random variable from ACRFrandom and ACRFshift helps achieve a desirable type II error.
Table 2 shows the type I error and type II error of ACRF/ACRFrandom and ACRFshift/ACRFshiftrandom (referred to as derandomized and randomized versions of ACRF/ACRFshift in Table 2). We observe that models with randomness and those without randomness achieve comparable type I errors when there is not shift in the inlier labels, while models with randomness tend to have worse type II errors and the final prediction set is more likely to contain multiple labels. One potential explanation for this is that randomization can help with the control of conditional coverage and may lead to increased high type II error due to this more ambitious goal. Supporting this, the randomized version for both ACRF and ACRFshift controls the type I error while the derandomized version, especially ACRF, shows inflated type I error under the label shift model.
Version | Method | no additional label shift | additional label shift | ||
Type I | Type II | Type I | Type II | ||
Randomized | ACRF | 0.0490.007 | 0.7020.017 | 0.0250.007 | 0.8840.014 |
ACRFshift | 0.0530.007 | 0.6810.014 | 0.0550.013 | 0.8280.015 | |
derandomized | ACRF | 0.0470.006 | 0.4310.003 | 0.1710.024 | 0.3130.067 |
ACRFshift | 0.0360.009 | 0.4390.009 | 0.0800.026 | 0.6300.127 |
Appendix C TRAINING DETAILS
In this section, we provide a detailed description of how we constructed datasets satisfying GLS and label shift using MNIST, CIFAR-10, and FashionMNIST for experimentation.
Q1 outliers w/o shift. For the datasets MNIST, CIFAR-10, and FashionMNIST, each consisting of 10 categories, we sampled 500 samples from each class (categories 0-5) to create a training set of 2500 samples. From the remaining samples in categories 0-5, we randomly selected 500 samples from each class, and similarly, we randomly selected 500 samples from each class in categories 6-9. These 5000 samples formed the test set. Notably, in the test set, categories 6-9 represent outliers that never appeared in the training set, while categories 0-5 are inlier samples.
Q2 shift w/o outliers. For the Label Shift setup, we sampled 500 samples from each class (categories 0-5) from MNIST, CIFAR-10, and FashionMNIST to create a training set of 3000 samples. From the remaining samples in categories 0-5, we randomly selected 100 samples from each class, and similarly, we randomly selected 500 samples from each class in categories 6-9. These 3000 samples formed the test set.
It is important to emphasize that for MNIST, CIFAR-10, and FashionMNIST, both CSForest and the baseline methods utilized representations extracted by a pre-trained ResNet-18 model as inputs, rather than the original images.
Appendix D ADDITIONAL EXPERIMENTS RESULTS
In the following section, we present additional experimental results to further substantiate the conclusions made in Section 4.
D.1 More Datastes
To further illustrate the effectiveness of CSForest under different tasks, we additionally include experiments on two new datasets: a cyber/network intrusion dataset from the KDD data competition and a chest X-ray dataset from the medical domain. Results in Tabel 3 shows CSForest achieves low type I errors and minimizes type II errors in both datasets, demonstrating its superior capability for outlier detection compared to the baseline.
Method | Network Intrusion | Chest X-ray | ||
Type I Error | Type II Error | Type I Error | Type II Error | |
CSForest | 0.048 0.013 | 9.524e-5 0.000 | 0.056 0.003 | 0.566 0.002 |
BCOPS | 0.047 0.014 | 5.905e-4 0.000 | 0.059 0.005 | 0.576 0.004 |
DC | 0.049 0.010 | 0.261 0.049 | 0.062 0.010 | 0.728 0.013 |
CRF | 0.030 0.004 | 0.467 0.104 | 0.039 0.033 | 0.793 0.178 |
ACRF | 0.000 0.000 | 0.857 0.000 | 0.067 0.046 | 0.922 0.005 |
ACRFshift | 0.001 0.001 | 0.019 0.004 | 0.039 0.049 | 0.885 0.057 |
D.2 Per-class Quality Evaluation
Figures 6 and 7 provide a detailed breakdown of the predictions made by all methods for each class in the CIFAR-10 and FashionMNIST datasets. Consistent with the results observed in MNIST, we find that CSForest is the top-performing method for outlier detection, and it avoids over-predicting by generating prediction sets that predominantly contain only the correct labels for each class.
D.3 Average Length of the Prediction Set
We observe that across all datasets, whether in the setting with outliers and no additional label shift or without outliers and with additional label shift, CSForest consistently achieves the smallest average prediction set interval length. This indicates that CSForest’s predictions do not contain a significant amount of redundant information, aligning with our previous observations of CSForest containing more “only correct labe” content for each class and exhibiting lower type II error.
To further illustrate that CSForest’s prediction set results in more accurate label predictions (i.e., predominantly containing only the correct labels) compared to other methods, Figure 8, 9(a) and 10(a) visualize the average interval length of prediction sets for all methods.
D.4 CSForest’s Performance with Varying Sample Size
In this section, we present the type II (inlier and outlier) error curves for all methods on CIFAR-10 and FashionMNIST as sample sizes vary. Consistent with the experimental results on MNIST, CSForest demonstrates superior outlier detection capabilities relative to the baseline as sample sizes change, and it also maintains lower inlier type II errors.
Appendix E DISCUSSION ON
To avoid oversampling, we impose constraints on , where the sample size for other classes is constrained to . That is, we weigh the training samples through sampling, and we will cap the influence of training samples if even taking all training samples becomes insufficient. So the threshold of satisfies . As a result, CSForest will yield the same Type I and Type II error once exceeds a certain threshold depending on the data.
Assuming a training dataset with classes and samples per class, and a test dataset with classes and samples per class. We have:
(18) | ||||
Based on eq. (18), we have the following conclusions:
-
1.
If exceeds the threshold , increasing will have no effect on CSForest.
-
2.
If the test sample size where is the training sample size, . In this case, greater than 1 will achieve the same errors as .
In this section, we experiment with different choices of weights from small to large (exceeding the weight threshold) as opposed to fixing at the default value. Although small can sometimes lead to improved outlier detection and large can sometimes improve the inlier classification, tend to provides a good tradeoff between these two objectives on the three real data sets considered.
E.1 MNIST
For the MNIST data, we consider and we can get the threshold . For the MNIST dataset, we indeed observed in Table 4 that once , the type I error and type II error of CSForest no longer change.
Type I Error | Type II Error (inlier) | Type II Error (outlier) | |
0 | 0.0570.018 | 0.2510.033 | 0.3140.068 |
LOG | 0.0530.016 | 0.2240.031 | 0.3150.061 |
1 | 0.0580.014 | 0.1190.018 | 0.3460.065 |
1.5 | 0.0550.016 | 0.1060.014 | 0.3490.068 |
2 | 0.0560.018 | 0.0990.016 | 0.3730.072 |
5 | 0.0560.018 | 0.0990.016 | 0.3730.072 |
10 | 0.0560.018 | 0.0990.016 | 0.3730.072 |
100 | 0.0560.018 | 0.0990.016 | 0.3730.072 |
E.2 CIFAR-10
For CIFAR-10, we consider and get the threshold . Similarly to MNIST, for CIFAR-10, once exceeds the threshold of 2, the performance of CSForest remains unchanged.
Type I Error | Type II Error (inlier) | Type II Error (outlier) | |
0 | 0.0450.015 | 0.0010.001 | 0.0000.000 |
LOG | 0.0430.016 | 0.0000.001 | 0.0000.000 |
1 | 0.0430.016 | 0.0000.001 | 0.0000.000 |
1.5 | 0.0430.014 | 0.0000.001 | 0.0000.000 |
2 | 0.0430.016 | 0.0000.001 | 0.0000.000 |
5 | 0.0430.016 | 0.0000.001 | 0.0000.000 |
10 | 0.0430.016 | 0.0000.001 | 0.0000.000 |
100 | 0.0430.016 | 0.0000.001 | 0.0000.000 |
E.3 FashionMNIST
For the CIFAR-10 data, we consider and get the threshold . For FashionMNIST as well, the performance of CSForest remains constant once surpasses the threshold of 2.
Type I Error | Type II Error (inlier) | Type II Error (outlier) | |
0 | 0.0490.011 | 0.4210.001 | 0.4060.045 |
LOG | 0.0480.012 | 0.3910.047 | 0.3990.043 |
1 | 0.0460.012 | 0.2870.028 | 0.4030.037 |
1.5 | 0.0470.010 | 0.2720.029 | 0.4080.038 |
2 | 0.0480.012 | 0.2620.032 | 0.4100.034 |
5 | 0.0480.012 | 0.2620.032 | 0.4100.034 |
10 | 0.0480.012 | 0.2620.032 | 0.4100.034 |
100 | 0.0480.012 | 0.2620.032 | 0.4100.034 |