probly.conformal_prediction.methods.mondrian

Mondrian and Class-Conditional Conformal Prediction.

Classes

GroupedConformalBase(model, group_func)

Base class for group based conformal prediction (Mondrian & Class-Conditional).

MondrianConformalClassifier(model, score, ...)

Mondrian (region-wise) conformal predictor for classification.

MondrianConformalRegressor(model, score, ...)

Mondrian (region-wise) conformal predictor for regression.

class probly.conformal_prediction.methods.mondrian.GroupedConformalBase(model, group_func)[source]

Bases: ConformalPredictor

Base class for group based conformal prediction (Mondrian & Class-Conditional).

Groups can be regions (Mondrian) or classes (ClassConditional). Shared calibrate() logic; subclasses implement predict().

Parameters:
static to_numpy(data)[source]

Convert tensor or array-like to numpy array.

Parameters:

data (Any)

Return type:

ndarray[Any, dtype[floating]]

calibrate(x_cal, y_cal, alpha)[source]

Calibrate group-wise thresholds on a calibration dataset.

Parameters:
Return type:

float

group_func: ClassFunc
group_thresholds: dict[int, float | np.floating]
group_thresholds_lower: dict[int, float | np.floating]
group_thresholds_upper: dict[int, float | np.floating]
is_asymmetric: bool
score: Score
class probly.conformal_prediction.methods.mondrian.MondrianConformalClassifier(model, score, region_func, use_accretive=False)[source]

Bases: GroupedConformalBase, ConformalClassifier

Mondrian (region-wise) conformal predictor for classification.

Parameters:
static to_numpy(data)

Convert tensor or array-like to numpy array.

Parameters:

data (Any)

Return type:

ndarray[Any, dtype[floating]]

calibrate(x_cal, y_cal, alpha)

Calibrate group-wise thresholds on a calibration dataset.

Parameters:
Return type:

float

predict(x_test, alpha, probs=None)[source]

Return Mondrian prediction sets.

Parameters:
Return type:

ndarray[Any, dtype[bool]]

group_func: ClassFunc
group_thresholds: dict[int, float | np.floating]
group_thresholds_lower: dict[int, float | np.floating]
group_thresholds_upper: dict[int, float | np.floating]
is_asymmetric: bool
is_calibrated: bool
nonconformity_scores: npt.NDArray[np.floating] | None
score: ClassificationScore
threshold: float | None
class probly.conformal_prediction.methods.mondrian.MondrianConformalRegressor(model, score, region_func)[source]

Bases: GroupedConformalBase, ConformalRegressor

Mondrian (region-wise) conformal predictor for regression.

Parameters:
static to_numpy(data)

Convert tensor or array-like to numpy array.

Parameters:

data (Any)

Return type:

ndarray[Any, dtype[floating]]

calibrate(x_cal, y_cal, alpha)

Calibrate group-wise thresholds on a calibration dataset.

Parameters:
Return type:

float

predict(x_test, alpha)[source]

Return Mondrian prediction intervals.

Parameters:
Return type:

ndarray[Any, dtype[floating]]

group_func: ClassFunc
group_thresholds: dict[int, float | np.floating]
group_thresholds_lower: dict[int, float | np.floating]
group_thresholds_upper: dict[int, float | np.floating]
is_asymmetric: bool
is_calibrated: bool
nonconformity_scores: npt.NDArray[np.floating] | None
score: RegressionScore
threshold: float | None