mapie.conformity_scores.NaiveConformityScore

class mapie.conformity_scores.NaiveConformityScore[source]

Naive classification non-conformity score method that is based on the cumulative sum of probabilities until the 1-alpha threshold.

Attributes
classes: Optional[ArrayLike]

Names of the classes.

random_state: Optional[Union[int, RandomState]]

Pseudo random number generator state.

quantiles_: ArrayLike of shape (n_alpha)

The quantiles estimated from get_sets method.

__init__() None[source]
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]

Get the quantiles of the conformity scores for each uncertainty level.

Parameters
conformity_scores: NDArray of shape (n_samples,)

Conformity scores for each sample.

alpha_np: NDArray of shape (n_alpha,)

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

estimator: EnsembleClassifier

Estimator that is fitted to predict y from X.

Returns
NDArray

Array of quantiles with respect to alpha_np.

get_conformity_scores(y: ndarray[Any, dtype[_ScalarType_co]], y_pred: ndarray[Any, dtype[_ScalarType_co]], **kwargs) ndarray[Any, dtype[_ScalarType_co]][source]

Get the conformity score.

Parameters
y: NDArray of shape (n_samples,)

Observed target values.

y_pred: NDArray of shape (n_samples,)

Predicted target values.

Returns
NDArray of shape (n_samples,)

Conformity scores.

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]

Generate prediction sets based on the probability predictions, the conformity scores and the uncertainty level.

Parameters
y_pred_proba: NDArray of shape (n_samples, n_classes)

Target prediction.

conformity_scores: NDArray of shape (n_samples,)

Conformity scores for each sample.

alpha_np: NDArray of shape (n_alpha,)

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

estimator: EnsembleClassifier

Estimator that is fitted to predict y from X.

Returns
NDArray

Array of quantiles with respect to alpha_np.

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

Get predictions from an EnsembleClassifier.

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, represents the uncertainty of the confidence interval.

estimator: EnsembleClassifier

Estimator that is fitted to predict y from X.

Returns
NDArray

Array of predictions.