mapie.conformity_scores.BaseClassificationScore

class mapie.conformity_scores.BaseClassificationScore[source]

Base conformity score class for classification task.

This class should not be used directly. Use derived classes instead.

Attributes
quantiles_: ArrayLike of shape (n_alpha)

The quantiles estimated from get_sets method.

__init__() None[source]
abstract get_conformity_score_quantiles(conformity_scores: ndarray[Any, dtype[_ScalarType_co]], alpha_np: ndarray[Any, dtype[_ScalarType_co]], estimator: EnsembleClassifier, **kwargs) ndarray[Any, dtype[_ScalarType_co]][source]

Abstract method to get quantiles of the conformity scores.

This method should be implemented by any subclass of the current class.

abstract get_prediction_sets(y_pred_proba: ndarray[Any, dtype[_ScalarType_co]], conformity_scores: ndarray[Any, dtype[_ScalarType_co]], alpha_np: ndarray[Any, dtype[_ScalarType_co]], estimator: EnsembleClassifier, **kwargs) ndarray[Any, dtype[_ScalarType_co]][source]

Abstract method to generate prediction sets based on the probability predictions, the conformity scores and the uncertainty level.

This method should be implemented by any subclass of the current class.

abstract get_predictions(X: ndarray[Any, dtype[_ScalarType_co]], alpha_np: ndarray[Any, dtype[_ScalarType_co]], estimator: EnsembleClassifier, **kwargs) ndarray[Any, dtype[_ScalarType_co]][source]

Abstract method to get predictions from an EnsembleClassifier.

This method should be implemented by any subclass of the current class.

get_sets(X: ndarray[Any, dtype[_ScalarType_co]], alpha_np: ndarray[Any, dtype[_ScalarType_co]], estimator: EnsembleClassifier, conformity_scores: ndarray[Any, dtype[_ScalarType_co]], **kwargs) ndarray[Any, dtype[_ScalarType_co]][source]

Compute classes of the prediction sets from the observed values, the estimator of type EnsembleClassifier and the conformity scores.

Parameters
X: NDArray of shape (n_samples, n_features)

Observed feature values.

alpha_np: NDArray of shape (n_alpha,)

NDArray of floats between 0 and 1, representing the uncertainty of the confidence set.

estimator: EnsembleClassifier

Estimator that is fitted to predict y from X.

conformity_scores: NDArray of shape (n_samples,)

Conformity scores.

Returns
NDArray of shape (n_samples, n_classes, n_alpha)

Prediction sets (Booleans indicate whether classes are included).

predict_set(X: ndarray[Any, dtype[_ScalarType_co]], alpha_np: ndarray[Any, dtype[_ScalarType_co]], **kwargs)[source]

Compute the prediction sets on new samples based on the uncertainty of the target confidence set.

set_external_attributes(*, classes: Optional[Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]] = None, random_state: Optional[Union[int, RandomState]] = None, **kwargs) None[source]

Set attributes that are not provided by the user.

Parameters
classes: Optional[ArrayLike]

Names of the classes.

By default None.

random_state: Optional[Union[int, RandomState]]

Pseudo random number generator state.