Introduction
In the current landscape of machine learning, performance is almost exclusively measured through predictive accuracy. Whether using Random Forests, Gradient Boosting, or Deep Neural Networks, the primary goal is typically to minimize the error rate. However, accuracy can be a deceptive metric. A model might achieve high accuracy while still failing to capture the underlying data-generating process—a phenomenon known as underfitting.
Traditional statistical methods offer "Goodness-of-Fit" (GOF) tests, such as the Hosmer-Lemeshow test, to determine if a model adequately describes the data. Yet, these classical tests were designed for parametric models like logistic regression and often lack the power or theoretical grounding to assess complex, non-parametric "black-box" classifiers. To bridge this gap, we introduce BAGofT (Binary Adaptive Goodness-of-fit Test), a framework designed to assess whether a general classification procedure is "good enough."
The BAGofT Methodology
The core challenge in testing non-parametric models is the lack of a fixed functional form. BAGofT overcomes this by utilizing a two-stage approach centered on data splitting and adaptive partitioning.
1. Data Splitting
The dataset is divided into a training set ($D_{n1}$) and a validation set ($D_{n2}$). This separation is crucial: it ensures that the search for model weaknesses does not bias the final statistical test, thereby controlling the Type I error rate.
2. Adaptive Partitioning (The Diagnostic Step)
The classification model under assessment is first trained on $D_{n1}$. To find where the model fails, BAGofT employs an "adversarial" diagnostic tool—typically a Random Forest—trained on the Pearson residuals of the initial model. These residuals represent the difference between the observed outcomes and the model's predicted probabilities. By fitting a secondary model to these errors, BAGofT identifies specific regions in the covariate space where the original model's predictions deviate most significantly from reality. It then adaptively partitions the data into groups that highlight these weaknesses.
3. Statistical Testing
Using the partitions identified in the diagnostic step, a Pearson-type test statistic is calculated using the independent validation set ($D_{n2}$). If the original model is a good fit, the observed responses in these regions should align with the predicted probabilities. A significant p-value indicates that the model has systematically missed patterns in the data (underfitting).
Key Insights: Beyond Accuracy
BAGofT shifts the focus from "how often is the model right?" to "is the model's representation of the data distribution correct?"
- Identifying Blind Spots: Unlike global metrics, BAGofT is inherently local. By partitioning the feature space, it can pinpoint which variables or interactions the model failed to learn. For instance, in experiments with the Fashion MNIST dataset, the tool identified that a simple neural network struggled specifically with the "gap between the legs" in images of trousers, a nuance it had not captured despite reasonable overall accuracy.
- Rate-Dependent Testing: The framework is flexible enough to test if a model is converging at a specific theoretical rate. This allows researchers to verify if a neural network is performing as expected given the complexity of the underlying data (e.g., specific Besov classes).
- Interpretability: The adaptive partition doesn't just provide a p-value; it reveals which variables are responsible for the underfitting, offering a roadmap for model improvement.
Empirical Results
The utility of BAGofT was demonstrated across several domains, showing significant advantages over traditional GOF tests.
Detecting Hidden Patterns
In a study involving Micro-RNA data for Alzheimer’s disease prediction (n=1309), BAGofT successfully rejected an underfitted model (p < 0.01) that omitted a critical principal component. In contrast, traditional tests like the Hosmer-Lemeshow and GRP tests failed to detect any issue, returning p-values greater than 0.17.
Accuracy vs. Fit in Medical Imaging
The most striking example of the "accuracy trap" appeared in the analysis of COVID-19 CT scan features. Two neural networks—one with a single neuron and one with seven—showed nearly identical accuracies of approximately 70%. However, BAGofT revealed a systematic defect in the 1-neuron network (p = 0.03), while the 7-neuron network was found to be a statistically adequate fit (p = 0.62). This demonstrates that BAGofT can distinguish between models that are "lucky" and models that are statistically sound.
Conclusion and Future Directions
BAGofT provides a much-needed rigorous framework for evaluating modern machine learning models. By using residuals to adaptively find model weaknesses, it offers both a statistical verdict and diagnostic interpretability.
Currently, the framework is optimized for binary classification and the detection of underfitting. Future work aims to extend these methods to multi-class problems and to develop complementary tests for overfitting. As machine learning continues to move into high-stakes fields like medicine and finance, tools like BAGofT will be essential for ensuring that our models are truly fit for purpose.
Summary updated