TL;DR
This paper introduces MAPIE, a Python library designed to provide flexible and systematic uncertainty estimation for machine learning models using conformal prediction. MAPIE aims to make state-of-the-art conformal prediction methods accessible and applicable across various tasks and data types, ensuring theoretical guarantees on prediction coverage.
What Problem Does This Paper Address?
In machine learning, simply predicting a single value (e.g., a house price) is often insufficient. For critical applications like medical diagnosis or financial forecasting, understanding the uncertainty associated with these predictions is paramount. This uncertainty quantification (UQ) is crucial for risk management, decision-making, and building trustworthy AI systems. While various UQ methods exist, many lack theoretical guarantees, are model-specific, or are difficult to implement. Conformal prediction (CP) offers a theoretically sound framework for UQ, providing marginal coverage guarantees, but its practical implementation can be complex and varied. This paper addresses the need for a unified, flexible, and easy-to-use library that implements diverse CP methods for both regression and classification tasks.
Methods
MAPIE is built around the principles of conformal prediction, offering a modular and extensible framework. Key methodological contributions and features include:
- Model and Task Agnosticism: MAPIE's core classes (
MapieRegressor,MapieClassifier) are designed to work with any scikit-learn-compatible model, allowing for UQ across diverse ML algorithms and tasks (regression, classification, time series). - Split and Cross-Conformal Strategies: The library implements both split-conformal (training/calibration split) and cross-conformal (using resampling techniques like K-Fold or Jackknife) methods. Cross-conformal methods offer a good balance between statistical and computational efficiency by avoiding data splitting.
- Flexible Non-Conformity Scores: A significant contribution is the extension of marginal coverage guarantees to a wider range of non-conformity scores beyond simple residuals. This includes "signed loss score functions" and "p-normalized residual non-conformity scores," which can adapt to heteroscedasticity and asymmetric errors.
- State-of-the-Art CP Methods: MAPIE integrates established CP methods such as Jackknife+, CV+, Jackknife+-after-bootstrap, and for classification, LABEL, APS, Top-K, and RAPS.
- Conformalized Quantile Regression (CQR): For handling heteroscedasticity, MAPIE includes CQR, a method that directly estimates prediction intervals by fitting quantile regressions.
- Ensemble Batch Prediction Intervals (EnbPI): For time series data, MAPIE implements EnbPI, which can dynamically update residuals to adapt to concept drift or change points.
Datasets
The paper evaluates MAPIE on several datasets:
- Toy Datasets:
- Homoscedastic noise dataset: Generated with a linear model and constant noise variance.
- Heteroscedastic noise dataset: Generated with a linear model where noise variance increases with the target value.
- House Price Dataset: A real-world dataset for predicting house prices, using 5 selected features from a larger set.
- Victoria Electricity Demand Dataset: A time series dataset used to demonstrate MAPIE's capabilities for dynamic time series with simulated change points.
- CIFAR10 Dataset: A standard benchmark for image classification, used to showcase MAPIE's application in this domain.
Key Insights and Ideas
- Non-conformity scores matter: The choice of non-conformity score significantly impacts prediction interval width and local coverage, especially in the presence of heteroscedasticity. For instance, p-normalized scores with p=0 (absolute residuals) are suitable for homoscedastic data, while p=2 can adapt to heteroscedasticity where noise scales with the prediction.
- CQR offers a robust alternative for heteroscedasticity: While p-normalized scores can adapt, CQR provides a more direct way to handle heteroscedasticity by modeling quantiles, striking a good balance between local coverage and interval width.
- MAPIE simplifies complex UQ: The library's scikit-learn-like API makes advanced CP methods accessible, allowing researchers and practitioners to easily experiment with different strategies and models.
- Theoretical guarantees are key: MAPIE's adherence to conformal prediction principles ensures that prediction intervals will achieve marginal coverage guarantees, providing a reliable measure of uncertainty.
Key Results
- Demonstrated Coverage: Experiments show that MAPIE methods, particularly CQR and adapted p-normalized scores, achieve good marginal and local coverage across various datasets, including those with heteroscedasticity and time series with change points.
- Impact of Non-conformity Scores: Figures illustrate how different non-conformity scores lead to varying prediction interval widths and coverage distributions, highlighting the importance of selecting the appropriate score for the data's noise characteristics.
- Time Series Adaptability: The EnbPI method in MAPIE effectively captures increased uncertainty after a simulated change point in electricity demand data, demonstrating its utility for dynamic environments.
- Classification Performance: For image classification, MAPIE's methods (LABEL, APS, Top-K) all achieve theoretical coverage guarantees, with differences in prediction set sizes, where the "score" method generally yields the smallest sets.
Limitations and Future Work
- Model Re-training for CQR: While CQR is effective for heteroscedasticity, it requires fitting separate quantile regressors, which might necessitate re-training or changing the base model, unlike methods directly integrated with the prediction function.
- Exchangeability Assumption: Most MAPIE methods assume data exchangeability, which is not always realistic for time series. The EnbPI method addresses this by relaxing this assumption with residual updates.
- Future Directions: The authors highlight several areas for future research and MAPIE development, including:
- Adaptive conformal inference.
- Handling covariate shift and label shift.
- Multi-target regression with copulas.
- Risk-controlling prediction sets and learn-then-test frameworks.
- Extending the library to support new conformal prediction methods through a modular API.
Summary updated