classifier.JackknifePlusClassifier

classifier.JackknifePlusClassifier(
    base_estimator=None,
    alpha=0.1,
    nonconformity_function=None,
    cv=None,
    random_state=None,
)

Cross-conformal classifier (jackknife+ / CV+ for classification).

Uses leave-one-out (cv=None) or K-fold cross-validation to compute held-out nonconformity scores, retains the per-fold estimators, and builds prediction sets at test time using Vovk’s cross-conformal p-values.

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.

nonconformity_function : callable = None

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

cv : int or None = None

Cross-validation strategy: - None: Leave-one-out (n model fits). - int: K-fold CV (cv model fits).

random_state : int = None

Random seed for K-fold shuffling. Ignored when cv is None.

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. Used by predict_proba() and predict_top_k(); not used to build prediction sets.

qhat_ : float

Backwards-compatible scalar threshold computed from calibration_scores_ using the split-conformal formula ⌈(n+1)(1−α)⌉/n quantile (with method='higher'). Reported for inspection only; not used by predict().

See Also

ConformalClassifier : Split conformal classifier (requires calibration set). CVPlusClassifier : Same algorithm; alternate name kept for parity with the regression API.

Methods

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

fit

classifier.JackknifePlusClassifier.fit(X, y)

Fit the cross-conformal classifier.

Parameters

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

Returns

self : JackknifePlusClassifier

predict

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

Cross-conformal prediction sets.

Parameters

X : array-like of shape (n_samples, n_features)
alpha : float, list of float, or None = None

Significance level(s). If None, uses self.alpha. If a scalar, returns list[list[int]]. If array-like, returns a boolean array of shape (n_samples, n_classes, n_alphas).

Returns

: list of list of int or ndarray

predict_proba

classifier.JackknifePlusClassifier.predict_proba(X)

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

predict_top_k

classifier.JackknifePlusClassifier.predict_top_k(X, k)

Top-K prediction sets (no coverage guarantee).

Returns the k most likely classes per sample, ordered by decreasing probability under the model refit on the full training data. This bypasses the cross-conformal machinery; coverage guarantees do not apply.

score

classifier.JackknifePlusClassifier.score(X, y)

Empirical coverage on test data.