arXiv:2610.12946stat.MLOct 2026

Manuscript Offprint

arXiv:2610.12946

From Imbalance to Evidence: Deep Nonparametric Testing for Complex Data under Severe Sample Imbalance

Guanhao Zhou, Xiufan Yu

Abstract

Comparing distributions under severe sample imbalance requires effectively using abundant majority observations while retaining sensitivity to differences involving the smaller sample. This challenge is particularly relevant for complex, non-Euclidean data, such as graphs, whose structural characteristics call for flexible testing procedures. Classifier two-sample tests (C2STs) provide such flexibility, but existing procedures are primarily designed for balanced or comparably sized samples. In this paper, we study C2STs in a highly imbalanced regime, and show that severe sample imbalance may substantially degrade testing performance. Different from conventional imbalanced learning approaches that treat sample imbalance merely as a nuisance for classifier training, we turn it into a source of repeated testing evidence. Building on this insight, we propose an Enhanced Imbalance-Aware Deep Classifier Two-Sample Test (EIAD-C2ST), a classifier-agnostic framework designed for sample imbalance that accommodates diverse data modalities by tailoring classifiers to data structure. For computationally expensive deep classifiers, we further develop a scalable representation-amortized implementation strategy. Theoretically, we establish rigorous guarantees on asymptotic size and characterize conditions for power consistency, allowing the imbalance ratio to diverge. We demonstrate the empirical gains using simulations and an application to blockchain forensics. The results reveal that the majority-sample surplus, when properly leveraged, can be organized into useful statistical evidence, rather than an obstacle, for distributional comparisons with complex data.

Keywords: Deep classifier; Exchangeable p-value aggregation; Inference for non-Euclidean data; Sample imbalance; Two-sample testing.

1 Introduction

Many consequential real-world problems exhibit severe class imbalance, and the rare observations are often those of greatest interest. This imbalance arises naturally in many scientific and societal processes, where outcomes or events may be inherently rare or disproportionately distributed (Chen et al., 2024). For instance, in fraud detection, fraudulent transactions are significantly fewer compared to legitimate activities (Pozzolo et al., 2014; Makki et al., 2019); in medical studies, especially those involving rare diseases or case-control designs, recruiting participants with a specific disease may be difficult due to low prevalence, cost constraints, or ethical considerations (Khushi et al., 2021; Wang et al., 2022). Related concerns arise in LLM safety and content moderation, where harmful, toxic, or adversarial jailbreak prompts represent only a small fraction of the vast volume of queries that deployed language models receive daily, yet their detection is critical for safe and responsible deployment (Gehman et al., 2020; Shen et al., 2024). In these settings, balanced data collection may be infeasible. Beyond predicting individual labels, an important inferential question is whether the observed characteristics follow the same distribution across the two populations. This question becomes particularly challenging when one population is scarcely represented, even if the pooled dataset is large.

Two-sample testing provides the statistical framework for this distributional comparison. Given two independent samples, the goal is to determine whether they are drawn from the same underlying distribution. Classical methods, including many recent high-dimensional procedures, often impose assumptions about the data-generating distributions, the geometry of the sample space, or the relationship between sample size and dimension (Lehmann and Romano, 2005; Huang et al., 2022). Most existing methods are primarily designed for structured Euclidean data. Modern datasets, however, increasingly involve complex data collected from irregular or complex domains (e.g., images, graphs, text, and audio), for which the structure of the observations is central to an informative comparison. When these data are also severely imbalanced, the methodological challenge is twofold: the test must accommodate the observation structure and use highly unequal samples effectively. This intersection of sample imbalance and structural complexity motivates a pressing need for flexible nonparametric testing procedures that require minimal distributional assumptions and can operate beyond conventional Euclidean data.

A related but distinct literature studies imbalanced learning and focuses on approaches to improving classifier performance (He and Garcia, 2009; Krawczyk, 2016). Representative approaches include resampling techniques (Chawla et al., 2002; Liu et al., 2008; Lemaitre et al., 2017), cost-sensitive learning (Elkan, 2001; Zhou and Liu, 2006), threshold adjustment (Sheng and Ling, 2006; Zou et al., 2016), and specialized loss functions (Lin et al., 2017; Cui et al., 2019). However, some of these remedies do not transfer directly to complex, non-Euclidean data. A prominent example is the Synthetic Minority Oversampling Technique (SMOTE) (Chawla et al., 2002), which faces several important challenges when applied to complex or high-dimensional data (Fernández et al., 2018). In particular, SMOTE generates synthetic minority samples by interpolating between nearest neighbors in a feature space. This construction implicitly assumes that Euclidean interpolation is meaningful, making it less suitable for non-Euclidean data such as graphs, text, audio, or other structured objects. In high-dimensional settings, SMOTE is further hampered by “the curse of dimensionality”, where the concentration of distances erodes the meaningfulness of nearest-neighbor relationships (Blagus and Lusa, 2013). Thus, complex data motivate imbalance-handling strategies that do not require synthesizing new observations in the original sample space. Furthermore, this literature primarily focuses on improving classifier fitting. Such predictive objectives, however, do not by themselves solve the inferential problem considered here.

For distributional inference, kernel-based methods provide an established class of flexible nonparametric tests, among which the Maximum Mean Discrepancy (MMD) test (Gretton et al., 2009, 2012; Schrab et al., 2023) is one of the most prominent. MMD measures distributional discrepancy by embedding probability distributions into a reproducing kernel Hilbert space and computing the distance between their mean embeddings. Although MMD is flexible and widely applicable, its empirical performance can be sensitive to kernel choice and hyperparameter tuning (Muandet et al., 2017; Ramdas et al., 2017). In recent years, Classifier Two-Sample Tests (C2STs) (Lopez-Paz and Oquab, 2017; Kim et al., 2021) have emerged as a powerful alternative and have gained increasing attention in the machine learning community. C2ST recasts two-sample testing as a classification problem: under the null hypothesis that the two distributions are identical, a well-calibrated classifier should perform no better than chance; under the alternative, systematic distributional differences provide predictive signals that enable the classifier to distinguish between the two samples. This formulation makes C2ST especially attractive for modern applications as it can leverage flexible machine-learning classifiers, including deep architectures, tailored to the data type.

Despite this flexibility, severe sample imbalance creates a challenge for C2ST that is fundamentally statistical rather than merely computational. Though the impact of class imbalance in classifier training can often be alleviated through techniques such as resampling, class weighting, threshold adjustment, or specialized loss functions, these strategies do not directly address the inferential goals and calibration requirements of two-sample testing. In C2ST, the goal is not only to train a classifier but also to construct a valid test statistic with proper calibration under the null. A classifier trained on highly imbalanced pooled data may allocate most of its capacity to the majority sample, weakening sensitivity to distributional departures. Moreover, raw classification accuracy can be misleading: a classifier may appear to perform well by primarily fitting the majority class, while failing to capture the distributional differences most relevant for testing. Empirically, we observe that the performance of C2ST can be substantially affected by the sample-size ratio and deteriorates in highly imbalanced situations; see Figure 1 for empirical evidence.

The severely imbalanced regime also calls for theoretical analysis beyond conventional proportional-sample-size settings. Representative C2ST analyses commonly consider equal sample sizes (Lopez-Paz and Oquab, 2017; Rosenblatt et al., 2021; Gerber et al., 2023), or at least samples of the same asymptotic order (Kim et al., 2021; Hediger et al., 2022; Cheng and Cloninger, 2022). Recent work has begun to consider two-sample testing under sample-size asymmetry (Chen et al., 2013; Tian et al., 2026), but this regime remains largely underexplored for classifier-based testing procedures.

This paper studies C2ST for complex, possibly non-Euclidean, data under severe sample imbalance. Our key idea is that, the surplus majority observations should not be viewed merely as a nuisance that complicates classifier training; rather, they can be exploited systematically as a statistical resource that can provide repeated testing evidence. Concretely, we partition the highly imbalanced dataset into multiple approximately balanced sub-datasets, each of which admits a more reliable classifier fit. We then evaluate these classifiers on a common held-out sample and aggregate their evidence while accounting for the dependence induced by shared observations. Unlike balanced-ensemble approaches in imbalanced classification, which use multiple balanced learners primarily to improve predictive performance, our construction uses the resulting balanced fits as building blocks of a hypothesis-testing procedure and explicitly calibrates and aggregates dependent testing evidence from those balanced fits. This strategy also fundamentally differs from standard imbalance remedies such as class weighting or oversampling: instead of modifying a single imbalanced classification problem, we repeatedly rebalance the data at the level of the testing procedure and then aggregate the resulting evidence across the subproblems. This rebalancing improves the reliability and power of C2ST while preserving its flexibility as to classifier choice and data modality.

Building on this insight, we propose the Imbalance-Aware Deep Classifier Two-Sample Test and its enhanced version, collectively referred to as (E)IAD-C2ST. For computationally expensive deep classifiers, we further develop a scalable implementation strategy, using representation amortization to reduce the computational burden of classifier training. The design logic, and therefore the attribution of power gains, consists of three components: balanced classifier fitting, which prevents class imbalance from dominating each classifier fit; blockwise evidence aggregation, which governs the use of the majority surplus; and train-test symmetrization, which governs the use of the two train-test orientations. The main contributions are summarized as follows.

References (59)