Conditional Conformal Prediction¶
Conformal prediction methods with conditional validity guarantees.
These estimators require the optional conditional dependency:
See Theory and the runnable regression and classification examples.
Conformalizers¶
mapie.conditional_conformal_prediction.ConditionalSplitConformalRegressor
¶
ConditionalSplitConformalRegressor(
feature_map: Callable,
estimator: RegressorMixin = LinearRegression(),
confidence_level: Union[float, Iterable[float]] = 0.9,
conformity_score: Union[
str, BaseRegressionScore
] = "absolute",
prefit: bool = True,
n_jobs: Optional[int] = None,
verbose: int = 0,
randomize: bool = False,
exact: bool = True,
infinite_params: Optional[dict] = None,
seed: int = 0,
)
Bases: _ConditionalConformalMixin, SplitConformalRegressor
Split conformal regressor with conditional validity guarantees.
In addition to the parameters of
:class:~mapie.regression.SplitConformalRegressor, this class accepts
settings for the conditional conformal procedure.
| PARAMETER | DESCRIPTION |
|---|---|
feature_map
|
Function mapping covariates to a finite basis used for exact conditional guarantees.
TYPE:
|
estimator
|
Base regressor used to predict points.
TYPE:
|
confidence_level
|
Desired coverage probability of the prediction intervals.
TYPE:
|
conformity_score
|
Method used to compute conformity scores. See
:class:
TYPE:
|
prefit
|
Whether the base regressor is already fitted.
TYPE:
|
n_jobs
|
Number of parallel jobs when applicable.
TYPE:
|
verbose
|
Verbosity level.
TYPE:
|
randomize
|
Whether to use randomization to make coverage exact rather than conservative. If False, predictions are deterministic and coverage may be slightly above the target level. If True, predictions use auxiliary randomness to match the target coverage level more exactly.
TYPE:
|
exact
|
Compute the conditional score cutoff exactly rather than by binary search.
TYPE:
|
infinite_params
|
Parameters for the RKHS component of the fit. Valid keys are
TYPE:
|
Source code in mapie/conditional_conformal_prediction.py
conformalize
¶
conformalize(
X_conformalize: ArrayLike,
y_conformalize: ArrayLike,
predict_params: Optional[dict] = None,
) -> "ConditionalSplitConformalRegressor"
Conformalize the regressor and set up the final fitting problem for the given conformalization set.
Performs the standard split-conformal conformalization step from
:meth:SplitConformalRegressor.conformalize, then builds the
cvxpy problem used for the conditional procedure.
| PARAMETER | DESCRIPTION |
|---|---|
X_conformalize
|
Features of the conformalization set.
TYPE:
|
y_conformalize
|
Targets of the conformalization set.
TYPE:
|
predict_params
|
Parameters to pass to the
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The conformalized ConditionalSplitConformalRegressor instance. |
Source code in mapie/conditional_conformal_prediction.py
predict_interval
¶
predict_interval(
X: ArrayLike,
minimize_interval_width: bool = False,
allow_infinite_bounds: bool = False,
) -> Tuple[NDArray, NDArray]
Predicts points (using the base regressor) and conditionally valid intervals.
If several confidence levels were provided during initialisation, several intervals will be predicted for each sample. See the return signature.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Features.
TYPE:
|
minimize_interval_width
|
Not supported by the conditional procedure; provided for API
compatibility with
:class:
TYPE:
|
allow_infinite_bounds
|
Accepted for API compatibility with
:class:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[NDArray, NDArray]
|
Two arrays:
|
Source code in mapie/conditional_conformal_prediction.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 | |
mapie.conditional_conformal_prediction.ConditionalSplitConformalClassifier
¶
ConditionalSplitConformalClassifier(
feature_map: Callable,
estimator: ClassifierMixin = LogisticRegression(),
confidence_level: Union[float, Iterable[float]] = 0.9,
conformity_score: Union[
str, BaseClassificationScore
] = "lac",
prefit: bool = True,
n_jobs: Optional[int] = None,
verbose: int = 0,
randomize: bool = False,
exact: bool = True,
infinite_params: Optional[dict] = None,
seed: int = 0,
)
Bases: _ConditionalConformalMixin, SplitConformalClassifier
Split conformal classifier with conditional validity guarantees.
In addition to the parameters of
:class:~mapie.classification.SplitConformalClassifier, this class
accepts settings for the conditional conformal procedure.
| PARAMETER | DESCRIPTION |
|---|---|
feature_map
|
Function mapping covariates to a finite basis used for exact conditional guarantees.
TYPE:
|
estimator
|
Base classifier used to predict labels.
TYPE:
|
confidence_level
|
Desired coverage probability of the prediction sets.
TYPE:
|
conformity_score
|
Method used to compute conformity scores. The conditional procedure inverts a real-valued score cutoff into a prediction set, so only scores whose prediction sets are obtained by thresholding real-valued scores are supported ("lac", "aps"); "top_k" and "raps" are not.
TYPE:
|
prefit
|
Whether the base classifier is already fitted.
TYPE:
|
n_jobs
|
Number of parallel jobs when applicable.
TYPE:
|
verbose
|
Verbosity level.
TYPE:
|
randomize
|
Whether to use randomization to make coverage exact rather than conservative. If False, predictions are deterministic and coverage may be slightly above the target level. If True, predictions use auxiliary randomness to match the target coverage level more exactly.
TYPE:
|
exact
|
Compute the conditional score cutoff exactly rather than by binary search.
TYPE:
|
infinite_params
|
Parameters for the RKHS component of the fit. Valid keys are
TYPE:
|
Source code in mapie/conditional_conformal_prediction.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 | |
conformalize
¶
conformalize(
X_conformalize: ArrayLike,
y_conformalize: ArrayLike,
predict_params: Optional[dict] = None,
) -> "ConditionalSplitConformalClassifier"
Conformalize the classifier and set up the final fitting problem for the given conformalization set.
Performs the standard split-conformal conformalization step from
:meth:SplitConformalClassifier.conformalize, then builds the
cvxpy problem used for the conditional procedure.
| PARAMETER | DESCRIPTION |
|---|---|
X_conformalize
|
Features of the conformalization set.
TYPE:
|
y_conformalize
|
Targets of the conformalization set.
TYPE:
|
predict_params
|
Parameters to pass to the
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The conformalized ConditionalSplitConformalClassifier instance. |
Source code in mapie/conditional_conformal_prediction.py
predict_set
¶
predict_set(
X: ArrayLike,
conformity_score_params: Optional[dict] = None,
) -> Tuple[NDArray, NDArray]
For each sample in X, predicts a label (using the base classifier) and a conditionally valid set of labels.
If several confidence levels were provided during initialisation, several sets will be predicted for each sample. See the return signature.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Features.
TYPE:
|
conformity_score_params
|
Parameters specific to conformity scores, used at prediction time
(e.g.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[NDArray, NDArray]
|
Two arrays:
|
Source code in mapie/conditional_conformal_prediction.py
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 | |