TL;DR
Conformal prediction gives machine learning models a superpower: prediction intervals with a strict, math-backed guarantee of being right—say, 90% of the time—no matter the model or sample size. However, an audit of 13 popular Python and R libraries reveals that tiny coding shortcuts silently shatter this guarantee in practice, while existing valid implementations are often painfully slow. Enter pyconformal, a unified, zero-bloat Python library that restores mathematical exactness and introduces clever algorithms that run up to thousands of times faster.
What Problem Does This Paper Address?
Machine learning models usually output point predictions without telling you how confident they are. Conformal prediction solves this by wrapping any model in a calibration step: you measure its errors on held-out data and pick a very specific rank—the $\lceil(n+1)(1-\alpha)\rceil$-th smallest error—to build your prediction interval. As long as your calibration and test data are exchangeable (roughly, drawn from the same distribution), that interval is mathematically guaranteed to cover the true answer at least $1-\alpha$ of the time.
Here is the catch: that mathematical proof belongs to that exact procedure. If a developer uses a standard empirical quantile without the finite-sample $(n+1)$ correction, returns a finite number when there aren't enough data points, or lets IEEE floating-point rounding nudge 0.1 into 0.10000000000000000555..., the guarantee evaporates. Furthermore, existing software splits tabular and time-series methods across incompatible ecosystems, and many reference implementations rely on naive loops or giant matrices that choke on large datasets.
Methods
pyconformal unifies roughly 30 conformal methods across regression, classification, calibration, time series, and panel data behind one clean API (fit, calibrate, predict_*, update), requiring only NumPy at runtime (with optional Numba compilation for speed).
Beyond clean software engineering, the author introduces genuine algorithmic upgrades:
- Exact Rational Arithmetic: All unweighted thresholds route through a single function that converts floating-point inputs into exact fractions before computing ceilings, completely eliminating off-by-one rank bugs caused by binary rounding.
- Integer-Hull Venn–Abers Calibration: Probability calibration via Venn–Abers usually requires quadratic-time slope recomputations.
pyconformalmaps scores onto a cumulative-sum diagram and walks precomputed prefix/suffix convex hulls using exact 64-bit integer cross-products. - Matrix-Free CV+ & Predictive Distributions: Instead of materializing massive $n_{\text{train}} \times n_{\text{test}}$ matrices, CV+ finds order statistics via binary-search pivoting inside sorted fold residuals, and predictive systems use prefix sums for closed-form metrics.
- Logarithmic Online Replay: Replaying historical time series uses Fenwick trees over pre-ranked scores, dropping per-step updates to $O(\log n)$.
- Repaired CIR/CIR+: Standard Conformal Interquantile Regression (CIR) scores calibration data one way and predicts another, breaking validity on bimodal data.
pyconformalenforces nested growing windows on both sides to restore the coverage proof.
Datasets
- Synthetic Data: Controlled, independent and identically distributed (i.i.d.) data—as well as drifting and bimodal distributions—were used for the software audits and speed benchmarks, ensuring any coverage failure could only stem from the conformal code itself.
- Public Tabular Datasets: Eight public datasets were used to evaluate
conformal-tightsand quantile-boosting wrappers. - Monash Time Series Archive: Three real-world series were tested: US daily births (7,305 days), Saugeen River daily flow (23,741 days), and Victoria hourly electricity demand. No new benchmark datasets were introduced.
Key Insights and Ideas
- Defaults can silently break math: Auditing 13 packages uncovered ~30 faults. Notably,
statsforecastandmlforecastdefault to just 2 calibration windows and use uncorrected percentiles; mathematically, 2 points can never support a finite 90% interval (max theoretical coverage is $2/3$). - Clipping kills adaptivity: Adaptive Conformal Inference (ACI) handles drifting time series by shifting its working error level—even below $0$ (yielding infinite intervals) when surprised. Both
MAPIEandTorchCPclip this level to $[0, 1]$, destroying the very drift guarantee ACI was invented for. - Subtle asymmetries ruin everything: Several libraries failed because calibration and prediction scored data slightly differently, or because nearest-neighbor difficulty estimators accidentally counted a calibration point as its own neighbor (making errors look artificially small).
- Core routines are mostly fine: Reassuringly, the basic, no-frills split-conformal regression and classification routines in
MAPIE,crepes,PUNCC, andTorchCPpassed every test. The bugs hide in newer modules, optional flags, and time-series extensions.
Key Results
- Audit Failures (at a 90% target / 10% miss rate): Default
statsforecast/mlforecastcovered only 61–66% on real and synthetic series.PUNCC's APS sets covered 45% when predicting one row at a time.TorchCP's CQR-R covered 57.6%, and clipped ACI miss rates hit 13.7–33.4% (MAPIE) and 14.0% (TorchCP) on drifting sequences. - Massive Speedups (with identical outputs):
- Venn–Abers on $10^6$ points: 0.37s vs. 75.0s in
venn-abers/MAPIE(205x faster). - Predictive intervals on $10^6$ test points: 0.01s vs. 79.2s in
crepes(8,100x faster). - Multi-step forecast intervals: 0.01s vs. 42s in R's
conformalForecast(>4,000x faster). - Replaying ACI history: ~2,000x faster than
MAPIE(shrinking to 6–8x in live, row-by-row streaming where model inference dominates). - Memory Savings: CV+ prediction on 20,000 test points needed 3 MB in
pyconformalversus 3.1 GB inMAPIE(at 5,000 training rows;MAPIEcrashed out of memory at 20,000).
Limitations and Future Work
- Hardware & Data Scope: Most coverage tests rely on synthetic data, and nearly all benchmarks were run on a single 2-core Linux machine.
- Unproven Worst-Case: While linear in practice and empirically stress-tested, the Venn–Abers tangent walk lacks a formal worst-case time complexity bound.
- Floating-Point Weights: The exact rational-arithmetic guarantee does not extend to weighted conformal methods, which still accumulate real-valued weights in standard floating point.
- Missing Methods: Future expansions could address current omissions, including conformal risk control, localized/clustered conditional methods, conformal anomaly detection, and exchangeability testing.
Summary updated