TL;DR
This paper introduces DetectShift, a novel, unified framework for diagnosing and quantifying various types of dataset shifts. It provides practitioners with a single tool to understand how data distributions change, enabling more informed decisions about model adaptation and retraining, especially when target data is scarce.
What Problem Does This Paper Address?
Machine learning models often assume that training data comes from the same distribution as the data they will encounter in the real world (the target distribution). However, in practice, this assumption frequently breaks down, leading to a phenomenon called "dataset shift." This shift can significantly degrade model performance. While various methods exist to detect specific types of dataset shifts (e.g., changes in features or labels), practitioners often lack a unified way to:
- Identify multiple types of shifts simultaneously: Is the shift in features, labels, or both?
- Quantify the magnitude of different shifts: How much has the feature distribution changed compared to the label distribution?
- Formally test for shifts: Go beyond visual inspection or heuristic measures to statistically validate the presence of a shift.
This lack of a comprehensive diagnostic tool makes it difficult for practitioners to understand the nature of the data changes and adapt their models effectively, particularly in scenarios with limited labeled target data.
Methods
The core of DetectShift lies in using Kullback-Leibler (KL) divergence as a measure of discrepancy between probability distributions. The framework defines and quantifies five types of dataset shifts:
- Total Dataset Shift ($P_{X,Y}$): Change in the joint distribution of features and labels.
- Feature Shift ($P_X$): Change in the distribution of features only.
- Response Shift ($P_Y$): Change in the distribution of labels only.
- Conditional Shift - Type 1 ($P_{X|Y}$): Change in the conditional distribution of features given labels.
- Conditional Shift - Type 2 ($P_{Y|X}$): Change in the conditional distribution of labels given features.
The framework proposes test statistics based on these KL divergences. To estimate these divergences, DetectShift employs a probabilistic classifier trained on an augmented dataset (combining source and target data) to predict the origin of a sample. This classifier's output is used to estimate the Radon-Nikodym derivative, which is crucial for calculating KL divergence.
For hypothesis testing, DetectShift uses permutation tests for unconditional shifts ($P_{X,Y}$, $P_X$, $P_Y$) and conditional randomization tests (CRT) for conditional shifts ($P_{X|Y}$, $P_{Y|X}$). These methods allow for formal hypothesis testing with controlled Type I error rates. A key innovation is the use of a unified approach for all shift types, allowing for direct comparison of their magnitudes.
Datasets
The paper evaluates DetectShift on several datasets:
- Artificial Data: Generated to isolate and test specific types of shifts.
- Credit Data: A real-world financial dataset from Latin America (Experian DataLab) containing one million Brazilians' financial data.
- MNIST and USPS: Standard image datasets for digit recognition, used to test performance on image data and adaptation strategies.
- Complex High-Dimensional Data:
- "Amazon Fine Food Reviews" (text data)
- Tiny ImageNet (image data)
- CIFAR-10 (image data)
- Regression Experiment Data: ENEM (Brazilian SAT) data from 2017-2020, focusing on students' math scores and socioeconomic features.
Key Insights and Ideas
- Unified Diagnostic Power: DetectShift provides a single, interpretable framework to diagnose all major types of dataset shifts, unlike many existing methods that focus on only one or two.
- Magnitude Comparison: By using test statistics of the same nature (KL divergence-based), the framework allows practitioners to directly compare the "strength" of different shifts, offering deeper insights into data changes.
- Adaptation Guidance: Identifying specific shifts (e.g., feature shift) can directly guide adaptation strategies, such as importance weighting, leading to better model performance, especially when target labels are scarce.
- High-Dimensional Robustness: The framework demonstrates good performance even in high-dimensional settings, outperforming some existing methods that struggle with dimensionality.
- Deep Model Compatibility: DetectShift can be seamlessly integrated with deep learning models, using them as feature extractors to estimate the necessary distributions.
Key Results
- Effective Shift Detection: DetectShift reliably detects various dataset shifts in both artificial and real-world experiments, including complex, high-dimensional, and deep learning scenarios.
- Superior Power for Conditional Shifts: In comparisons with existing methods, DetectShift showed significantly higher power for detecting conditional shifts (Type 1 and Type 2) while maintaining comparable power for marginal shifts.
- High-Dimensional Performance: The framework scales well to high-dimensional data, with performance degradation being less severe compared to some alternative methods (e.g., Total Variation distance).
- Improved Model Adaptation: Experiments on MNIST/USPS and credit data showed that adapting models based on DetectShift's insights (e.g., addressing feature shift) led to better predictive performance on target domains.
- Interpretable Diagnostics: The framework provides interpretable results, allowing practitioners to understand why a model might be failing and how to fix it. For instance, in the credit data experiment, a decoupling of shifts was observed around the COVID-19 pandemic, suggesting a significant change in label distributions.
Limitations and Future Work
- Radon-Nikodym Derivative Estimation: The power of the tests depends on the accuracy of the estimated Radon-Nikodym derivatives. The paper suggests using cross-entropy loss on a validation set to select the best classifier for this estimation.
- Labeled Data in Target Domain: While the framework is particularly useful when target labels are scarce, it acknowledges that scenarios with no labeled target data are a limitation that warrants further exploration.
- Streaming Data: The current framework is not designed for streaming data but can be adapted by processing data in batches.
- Alternative Statistics: The framework is modular and can accommodate alternative statistics beyond KL divergence, such as symmetrized KL, for different use cases.
Summary updated