Repository navigation
Use the finite-sample conformal quantile in conformal models - #3227
Merged
dennisbader merged 6 commits intoOct 12, 2026
Merged
dennisbader merged 6 commits into
dennisbader merged 6 commits into
Conversation
Contributor
Author
|
Hi @dennisbader, a gentle ping on this PR when you have a moment. Happy to adjust anything if needed. Thanks! |
…nformal-finite-sample-quantile # Conflicts: # CHANGELOG.md
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3227 +/- ##
=======================================
Coverage 97.14% 97.14%
=======================================
Files 174 174
Lines 19299 19304 +5
=======================================
+ Hits 18748 18753 +5
Misses 551 551 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
dennisbader
approved these changes
Oct 12, 2026
dennisbader
left a comment
Collaborator
There was a problem hiding this comment.
Thanks a lot for fixing this and your first contribution @nicoloangileri 🚀
Everything looks good to 💯
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist before merging this PR:
There is no open issue for this; the details are below.
Summary
ConformalNaiveModelandConformalQRModelcompute the interval correction asnp.quantile(scores, q=alpha, method="higher")over thencalibration scores. That is the(ceil((n - 1) * alpha) + 1)-th smallest score. Split conformal prediction takes theceil((n + 1) * alpha)-th smallest score, which is what gives coverage of at leastalphafor exchangeable scores (Vovk et al. 2005; Lei et al. 2018; Angelopoulos & Bates 2021). Foralpha > 0.5the current rank can be one lower, and then the interval under-covers.With
cal_length=12and quantiles[0.05, 0.5, 0.95](a 90% interval), the current rule picks the 11th of 12 scores, so the guaranteed coverage is 11/13 = 84.6%. For a 90% interval the guarantee drops below 90% for 156 of the values ofnbetween 5 and 200.Empirical coverage on i.i.d. N(0, 1) series, with a
LinearRegressionModel(lags=1)fitted on separate data andConformalNaiveModel(quantiles=[0.05, 0.5, 0.95], cal_length=n). The numbers are one-stephistorical_forecastsover 20 series of length 1200, scored withmic(q_interval=(0.05, 0.95)):nrank/(n+1)aftern)Changes:
_conformal_quantile()inconformal_models.py, used by both models. It selects theceil((n + 1) * alpha)-th smallest score. When that rank is larger thann(i.e.n < alpha / (1 - alpha)), it uses the largest score, which is what happens today. Selecting the rank goes throughnp.quantile(..., method="nearest")at the exact positionrank - 1, so NaN handling is unchanged. I checked this against a sort-based selection for everynup to 1499 and 10 levels.helper_compute_pred_calbuilds the expected intervals with the same rule, via an independent sort-basedhelper_conformal_quantile.test_single_tsasserts that predicting with a differentnchanges the result. With the 17-point series and an 80% interval, both predictions now select the largest of the few residuals per step, so that check uses a narrower interval[0.3, 0.5, 0.7]. It passes before and after the change.test_finite_sample_conformal_quantile(symmetric and asymmetric): with 12 calibration residuals and an 80% interval, the half-widths are the 11th smallest absolute error (symmetric) and the 12th smallest error per tail (asymmetric). It fails on master.test_conformal_model.py: 738 passed.ruff0.7.2 check and format pass.Other Information
The intervals get slightly wider only when the old rank was lower than
ceil((n + 1) * alpha). For largenthe difference disappears.