pitcp.models.SCP¶
- class SCP[source]¶
Calibrates scalar nonconformity scores by split conformal prediction.
- Calibration settings:
s: Held-out scalar nonconformity scores used to compute the finite-sample corrected empirical quantiles.
- Prediction settings:
X: Test features. Only the number of samples is used because split conformal thresholds do not depend on the feature values.confidence_level: Target marginal coverage level or sequence of levels in the open interval from zero to one. Defaults to 0.9.
- Variables:
scores (np.ndarray) – Held-out calibration scores with shape
(n_samples,).
- __init__()¶
- conformalize(s)[source]¶
Stores held-out calibration scores.
- Parameters:
s (np.typing.ArrayLike) – Scores with shape
(n_samples,).- Returns:
The calibrated estimator.
- Return type:
Self
- fit(s)¶
Stores held-out calibration scores.
- Parameters:
s (np.typing.ArrayLike) – Scores with shape
(n_samples,).- Returns:
The calibrated estimator.
- Return type:
Self
- thresholds(confidence_level=0.9)[source]¶
Computes finite-sample corrected score thresholds.
- Parameters:
confidence_level (float | Sequence[float], optional) – Target marginal coverage level or levels. Defaults to 0.9.
- Returns:
One threshold for each requested confidence level.
- Return type:
np.ndarray
- predict(X, *, confidence_level=0.9)[source]¶
Returns score-space thresholds for test features.
- Parameters:
X (np.typing.ArrayLike) – Test features with shape
(n_samples, n_features).confidence_level (float | Sequence[float], optional) – Target marginal coverage level or levels. Defaults to 0.9.
- Returns:
- Score thresholds with shape
`(n_samples,)or ``(n_samples, n_levels)``.
- Score thresholds with shape
- Return type:
np.ndarray
- contains(s, *, confidence_level=0.9)[source]¶
Tests whether scores lie inside calibrated regions.
- Parameters:
s (np.typing.ArrayLike) – Test scores with shape
(n_samples,).confidence_level (float | Sequence[float], optional) – Requested coverage levels. Defaults to 0.9.
- Returns:
- Coverage indicators with shape
(n_samples,)or ``(n_samples, n_levels)``.
- Coverage indicators with shape
- Return type:
np.ndarray
- set_fit_request(*, s='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
s (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sparameter infit.self (SCP)
- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, confidence_level='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
confidence_level (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
confidence_levelparameter inpredict.self (SCP)
- Returns:
self – The updated object.
- Return type:
object