Conditional conformal regression¶
Conformal prediction intervals with conditional coverage over any user-specified feature or overlapping subgroup basis \(\Phi(X)\) — powered by pyconformal's fast pure-NumPy linear quantile regression.
| Use it when | You want simultaneous conditional coverage across overlapping demographic groups, splines, or continuous feature slices where Mondrian groups= cannot overlap. |
| Guarantee | Exact finite-sample marginal coverage \(\ge 1 - \alpha\) (when frac_fit > 0) plus conditional coverage across the span of \(\Phi(X)\). |
| In the library | ConditionalConformalRegressor |
| Source | Gibbs, Cherian and Candès (JRSS-B 2025) |
| Example needs | pyconformal |
Marginal & subgroup-conditional guarantee
ConditionalConformalRegressor fits linear quantile regression of calibration residuals on \(\Phi(X)\) at level \(1 - \alpha\) via linear_quantile_regression, followed by an exact finite-sample conformal shift on the disjoint calibration split.
Minimal example¶
Copy, paste, run.
import numpy as np
from pyconformal import ConditionalConformalRegressor
from pyconformal.point_models import Ridge
rng = np.random.default_rng(0)
n = 1500
g1 = rng.integers(0, 2, size=n).astype(float)
g2 = rng.integers(0, 2, size=n).astype(float)
x = rng.normal(size=n)
y = 2.0 * x + rng.normal(0.0, 0.5 + 1.5 * g1 + 1.2 * g2)
X = np.column_stack([x, g1, g2])
phi = np.column_stack([g1, g2, g1 * g2])
model = Ridge(alpha=1.0).fit(X[:400], y[:400])
ccr = ConditionalConformalRegressor(model, alpha=0.1, random_state=0)
ccr.calibrate(X[400:1000], y[400:1000], phi=phi[400:1000])
iv = ccr.predict_interval(X[1000:], phi=phi[1000:])
cov = (y[1000:] >= iv[:, 0]) & (y[1000:] <= iv[:, 1])
print(f"overall: {cov.mean():.3f} g1=1: {cov[g1[1000:] == 1].mean():.3f} g2=1: {cov[g2[1000:] == 1].mean():.3f}")
More¶
- Full argument list: API reference
- All methods: what's inside