xpectra.AbstainingClassifier

class xpectra.AbstainingClassifier(model, scorer)[source]

Bases: object

Predict a class when the OOD score is below tau, otherwise abstain.

Parameters:

scorer (OODScorer)

__init__(model, scorer)[source]
Parameters:

scorer (OODScorer)

Return type:

None

Methods

__init__(model, scorer)

achieved_coverage(X)

Fraction of X that would be classified (not abstained) at the current tau.

fit_tau(X_val[, target_coverage])

Set tau so that target_coverage of X_val falls below it.

predict(X, class_names)

Attributes

ABSTAIN

ABSTAIN = 'ABSTAIN'
fit_tau(X_val, target_coverage=0.9)[source]

Set tau so that target_coverage of X_val falls below it.

X_val must be a HELD-OUT labeled set that neither the model nor the scorer was trained on — calibrating on in-sample data yields optimistic scores and a threshold too tight to hit the target coverage on new data.

Parameters:
Return type:

AbstainingClassifier

achieved_coverage(X)[source]

Fraction of X that would be classified (not abstained) at the current tau.

Parameters:

X (ndarray)

Return type:

float

predict(X, class_names)[source]
Parameters:
Return type:

tuple[ndarray, ndarray]