incerto.conformal.conformalized_quantile_regression#
- incerto.conformal.conformalized_quantile_regression(quantile_model, calib_loader, alpha, q_low=None, q_high=None)[source]#
Conformalized Quantile Regression (CQR) — Romano, Patterson, and Candes, NeurIPS 2019.
Combines quantile regression with split conformal prediction to produce adaptive prediction intervals with finite-sample coverage guarantees.
The method works by: 1. Training a quantile regression model to predict lower and upper quantiles 2. Computing conformity scores on a calibration set as the maximum violation 3. Using these scores to adjust the quantile predictions
- Parameters:
quantile_model (
Module) – A model that outputs (lower_quantile, upper_quantile) predictions. Expected to output shape (batch_size, 2) where: - [:, 0] is the lower quantile prediction - [:, 1] is the upper quantile predictioncalib_loader (
DataLoader) – DataLoader for calibration dataalpha (
float) – Miscoverage rate (e.g., 0.1 for 90% coverage)q_low (
Optional[float]) – Lower quantile level (default: alpha/2)q_high (
Optional[float]) – Upper quantile level (default: 1 - alpha/2)
- Returns:
Function mapping inputs to (lower, upper) prediction intervals
- Return type:
predictor
- Reference:
Romano, Patterson, and Candes. “Conformalized Quantile Regression.” NeurIPS 2019. https://arxiv.org/abs/1905.03222
Example
>>> # Train quantile model (outputs lower and upper quantiles) >>> quantile_net = QuantileRegressionNet() >>> # ... train quantile_net ... >>> predictor = conformalized_quantile_regression( ... quantile_net, calib_loader, alpha=0.1 ... ) >>> lower, upper = predictor(test_x)