classifier.CVPlusClassifier

classifier.CVPlusClassifier(
    base_estimator=None,
    alpha=0.1,
    n_splits=5,
    nonconformity_function=None,
    random_state=None,
    verbose=0,
)

CV+ (cross-conformal) conformal classifier.

Wraps JackknifePlusClassifier with K-fold cross-validation. Per-fold estimators are retained, and prediction sets are built at test time from cross-conformal p-values rather than from a single quantile threshold applied to a refit-on-full-data model.

Parameters

base_estimator : estimator = None

Base classifier implementing fit() and predict_proba().

alpha : float = 0.1

Significance level. Labels with p-value strictly greater than alpha are included in the prediction set.

n_splits : int = 5

Number of cross-validation folds. Must be >= 2.

nonconformity_function : callable = None

Function with signature (y_true, y_prob) -> scores.

random_state : int = None

Random seed for K-fold shuffling.

verbose : int = 0

Verbosity level.

Attributes

estimators_ : list of estimators

Per-fold fitted models.

fold_assignment_ : ndarray of shape (n_samples,)

Index into estimators_ of the held-out estimator for each training sample.

calibration_scores_ : ndarray of shape (n_samples,)

Nonconformity scores from held-out predictions.

classes_ : ndarray

Unique class labels (sorted).

n_classes_ : int

Number of classes.

model_ : estimator

Base estimator refit on the full training data.

qhat_ : float

Backwards-compatible scalar threshold (not used by predict()).

Notes

The cross-conformal coverage guarantee for classification is P(Y ∈ C(X)) ≥ 1 − 2α (Vovk 2015, analogous to Barber et al. 2021 for the regression jackknife+). Empirical coverage is typically much closer to 1 − α.

Methods

Name Description
fit Fit the CV+ classifier.
predict Cross-conformal prediction sets. See
predict_proba Class probabilities from the model refit on the full training set.
predict_top_k Top-K prediction sets (no coverage guarantee). See
score Empirical coverage on test data.

fit

classifier.CVPlusClassifier.fit(X, y)

Fit the CV+ classifier.

Parameters

X : array-like of shape (n_samples, n_features)
y : array-like of shape (n_samples,)

Returns

self : CVPlusClassifier

predict

classifier.CVPlusClassifier.predict(X, *, alpha=None)

Cross-conformal prediction sets. See JackknifePlusClassifier.predict.

predict_proba

classifier.CVPlusClassifier.predict_proba(X)

Class probabilities from the model refit on the full training set.

predict_top_k

classifier.CVPlusClassifier.predict_top_k(X, k)

Top-K prediction sets (no coverage guarantee). See JackknifePlusClassifier.predict_top_k.

score

classifier.CVPlusClassifier.score(X, y)

Empirical coverage on test data.