incerto.conformal.ConformalPredictor#

class incerto.conformal.ConformalPredictor(predictor, method='unknown', alpha=0.0)[source]#

Bases: object

Thin wrapper around a calibrated conformal predictor.

Provides a consistent object-oriented interface for both classification (prediction sets) and regression (intervals) conformal methods.

Parameters:
  • predictor (Callable) – Callable returned by a conformal method function.

  • method (str) – Name of the conformal method used.

  • alpha (float) – Miscoverage rate used during calibration.

Example

>>> cp = ConformalPredictor.from_method(
...     "raps", model=model, calib_loader=loader, alpha=0.1
... )
>>> pred_sets = cp.predict(x_test)
__init__(predictor, method='unknown', alpha=0.0)[source]#
Parameters:

Methods

__init__(predictor[, method, alpha])

from_method(method, **kwargs)

Convenience factory that calls the named method and wraps the result.

predict(x)

Run the calibrated predictor on new inputs.

__init__(predictor, method='unknown', alpha=0.0)[source]#
Parameters:
predict(x)[source]#

Run the calibrated predictor on new inputs.

For classification: returns List[torch.Tensor] of prediction sets. For regression: returns (lower, upper) interval bounds.

Parameters:

x (Tensor)

Return type:

Union[List[Tensor], Tuple[Tensor, Tensor]]

classmethod from_method(method, **kwargs)[source]#

Convenience factory that calls the named method and wraps the result.

Parameters:
  • method (str) – One of 'inductive_conformal', 'mondrian_conformal', 'aps', 'raps', 'jackknife_plus', 'cv_plus', 'conformalized_quantile_regression'.

  • **kwargs – Arguments forwarded to the method function.

Return type:

ConformalPredictor

Returns:

A ConformalPredictor wrapping the calibrated predictor.