[KongchangAI]
· 3 min read· 1,557 words

pyconformal: Precise and Fast Conformal Prediction — After Auditing 13 Packages, He Built a New Wheel

pyconformal: Precise and Fast Conformal Prediction — After Auditing 13 Packages, He Built a New Wheel

An audit of 13 conformal prediction packages found ~30 defects and led to the rigorously validated pyconformal library.

The article reports a systematic audit of 13 Python and R conformal prediction packages, finding about 30 implementation defects, including default calibration windows that yield only 63% coverage for a 90% target, row-by-row coverage dropping to 45%, and adaptive methods truncating the working level. These show that library defaults may not satisfy theoretical guarantees. The author thus released pyconformal, implementing ~30 conformal methods under a unified interface, each triple-tested against definition, reference code, and statistical guarantee, with optimizations like integer-arithmetic Venn-Abers kernels, rank trees, and closed-form solutions. Benchmarks show Venn-Abers on a million points in 0.37s (reference 75s) and CV+ using 3MB (MAPIE needs 3GB). Practitioners are reminded not to assume default reliability and to validate coverage for critical applications.

Title

pyconformal: Precise and Fast Conformal Prediction — After Auditing 13 Packages, He Built a New Wheel

Meta Description

An audit of 13 conformal prediction packages uncovered about 30 defects. The author introduces pyconformal: a unified interface implementing ~30 methods, Venn-Abers calibration on a million points in just 0.37 seconds, and CV+ using only 3 MB of memory.

Article Content

The core value of conformal prediction lies in its statistical guarantee: as long as the calibration data and test data are exchangeable, a 90% split-conformal interval will cover at least 90% of true values—regardless of the model you use or the size of the calibration set. But this guarantee belongs to an "exact" procedure, and software implementations often lose it due to inconspicuous design choices.

Recently, a developer conducted a systematic audit of 13 Python and R conformal prediction packages, reading the code of 5 libraries module by module, and found about 30 defects. Two prediction libraries, under their default two calibration windows, achieved only 63% coverage for a 90% target; another library, when predicting row by row, had prediction set coverage of only 45%; and two implementations of adaptive conformal inference truncated the working level, directly discarding the method's own guarantee. However, the basic split-conformal routines of mainstream libraries achieved nominal levels in all tests.

Based on this audit, the author released pyconformal—an MIT-licensed package that implements about 30 conformal methods through a unified interface, covering regression, classification, probabilistic calibration, predictive distributions, time series, and panel data. Each method is tested against its definition, reference code (if available), and statistical guarantee.

pyconformal project screenshot

Audit Findings: How Guarantees Are Lost

The guarantee of conformal prediction is finite-sample and exact, but small implementation choices can silently break it. The problems exposed by the audit are concentrated in several areas:

  • Insufficient default calibration windows: Two prediction libraries use only two calibration windows by default, resulting in actual coverage of only 63% for a 90% target. This reminds us that default parameters may not deliver on theoretical promises.
  • The pitfall of row-by-row prediction: One library's prediction set coverage dropped to 45% when predicting row by row, far below the target level.
  • Truncation errors in adaptive methods: Two implementations of adaptive conformal inference truncated the working level, so the methods no longer carry the guarantee in their definition.

These defects do not stem from theoretical complexity but from detailed oversights in engineering implementation. For systems that rely on conformal prediction for decision-making, such coverage deviations can bring real risks.

Exchangeability is the cornerstone of the statistical guarantee of conformal prediction. It is weaker than independent and identically distributed (i.i.d.): it only requires that the joint distribution of the calibration set and the test point be insensitive to permutation order, i.e., the probability of any rearrangement of these samples remains unchanged. Once the data has temporal trends, distribution drift, or group structure, exchangeability may be broken, and even a perfectly correct implementation cannot deliver nominal coverage. The finite-sample exact guarantee of split-conformal holds precisely under this assumption. Therefore, in addition to implementation defects, the cases of severe coverage deviation in the audit remind practitioners to first test whether the data satisfies exchangeability before discussing the reliability of coverage.

Split-conformal and calibration windows: Split-conformal divides data into a training set and a calibration set, and constructs prediction intervals using nonconformity scores on the calibration set. Its coverage guarantee depends on the size of the calibration set: the smaller the calibration set, the larger the finite-sample correction term and the wider the interval. If an implementation uses only two calibration windows by default (i.e., very few calibration samples), the limited calibration scores cannot reliably estimate quantiles, and coverage will deviate severely from the nominal level. The case in the audit where a 90% target achieved only 63% coverage is a typical manifestation of quantile estimation bias caused by an overly small calibration set. This also shows that the choice of default parameters must match the finite-sample correction of the statistical guarantee.

Design of pyconformal: One Interface, Thirty Methods

pyconformal aims to give users access to multiple conformal methods under one interface while ensuring that each method is rigorously validated. The author emphasizes that each method is tested against three standards: definition, reference code (if available), and statistical guarantee. This "triple validation" is not common among conformal prediction libraries.

The types of methods covered by the package include:

  • Conformal prediction for regression and classification
  • Probabilistic calibration (e.g., Venn-Abers)
  • Predictive distributions
  • Time series and panel data

The unified interface lowers the barrier to use and facilitates cross-method comparison. But what is more noteworthy is the improvements the author made at the algorithm level.

Venn-Abers calibration is a method for probabilistic calibration based on the Venn predictor framework. It constructs a conformal predictor for each possible label and maps raw scores to calibrated probabilities through isotonic regression. Its core is to guarantee the calibration of output probabilities, i.e., predicted probabilities match actual frequencies. Traditional implementations involve a large number of iterations and sorting operations, resulting in high computational complexity; pyconformal optimizes the kernel computation of isotonic regression using integer arithmetic and closed-form solutions, achieving a two-order-of-magnitude speedup on million-scale data while keeping the output exactly identical to the reference implementation.

Algorithmic Improvements: Significant Gains in Speed and Memory

pyconformal is not just a wrapper around existing methods; it also introduces algorithmic optimizations that greatly improve performance while keeping outputs consistent.

  • Exact Venn-Abers kernel with integer arithmetic: On a million points, Venn-Abers calibration takes only 0.37 seconds, while the reference implementation takes 75 seconds.
  • Rank trees for online methods: Provides a more efficient data structure for online conformal methods.
  • Closed-form solution for conformal predictive distributions: Avoids iterative computation.
  • Memory optimization for CV+: The implementation requires only 3 MB of memory, whereas MAPIE requires 3 GB.
  • Fixed conformal quantile regression rule: Corrects problems in existing implementations.

These improvements are not fine-tuning. For Venn-Abers, the speedup is two orders of magnitude; for CV+, memory usage is reduced by three orders of magnitude. For large-scale data or resource-constrained environments, this difference can be decisive.

CV+ is a conformal method based on cross-validation for regression problems. It divides data into K folds, trains a model on each fold, constructs nonconformity scores using residuals on the held-out fold, and finally aggregates scores across folds to obtain prediction intervals. The advantage of CV+ is that it can use all data to train models while maintaining approximately valid coverage. However, standard implementations need to store model predictions and score matrices for all folds, and memory overhead grows linearly with sample size. pyconformal optimizes memory usage through streaming aggregation and in-place computation, requiring only 3 MB on million-scale data, compared with 3 GB for MAPIE—a reduction of three orders of magnitude.

Benchmarks: Performance on Million-Scale Data

The author provides two concrete benchmark results, both compared with reference implementations:

  1. Venn-Abers calibration: On a million points, pyconformal takes 0.37 seconds, while the reference implementation takes 75 seconds, with identical output.
  2. Conformal prediction intervals: For a million test points, pyconformal takes 0.01 seconds, while crepes takes 79 seconds.

These numbers demonstrate the practical benefits of the algorithmic improvements. Note that these tests were conducted under specific conditions, but the order-of-magnitude gaps are sufficient to make the point.

Implications for Practitioners

This audit and the release of pyconformal serve as a reminder to practitioners using conformal prediction: do not assume that a library's default behavior necessarily satisfies theoretical guarantees. Even for the most basic split-conformal, implementations across libraries may differ subtly. When choosing a library, beyond looking at the feature list, pay attention to whether it has been validated against guarantees.

pyconformal's rigorous testing framework and algorithmic optimizations provide a new option for scenarios requiring reliable conformal prediction. But the author also admits that the audit covered only 13 packages, and more issues may remain undiscovered. For critical applications, independently validating coverage remains a necessary step.

The value of conformal prediction lies in its guarantee, and the guarantee needs precise implementation to be delivered. pyconformal attempts to find a balance between "precise" and "fast," and its audit results also remind us: software details determine whether guarantees succeed or fail.

One-line Summary

An audit of 13 conformal prediction packages found about 30 defects and led to the rigorously validated pyconformal library.

Paragraph Summary

The article reports a systematic audit of 13 Python and R conformal prediction packages, finding about 30 implementation defects, including insufficient default calibration windows causing a 90% target to achieve only 63% coverage, row-by-row prediction coverage dropping to 45%, and adaptive methods truncating the working level. These defects show that library defaults may not satisfy theoretical guarantees. To address this, the author released pyconformal, which implements about 30 conformal methods under a unified interface, with each method triple-tested against its definition, reference code, and statistical guarantee, and with algorithmic optimizations such as integer-arithmetic Venn-Abers kernels, rank trees, and closed-form solutions that greatly improve speed and memory efficiency. Benchmarks show Venn-Abers calibration on a million points takes only 0.37 seconds (reference: 75 seconds), and CV+ uses 3 MB of memory (MAPIE requires 3 GB). The article reminds practitioners not to assume default behavior is reliable and that critical applications still require independent coverage validation.

#conformal prediction#pyconformal#Venn-Abers#CV+#statistical guarantee#calibration
Share:

Related articles