autointent.modules.decision.JinoosDecision#

class autointent.modules.decision.JinoosDecision(search_space=None)#

Bases: autointent.modules.abc.DecisionModule

Jinoos predictor module.

JinoosDecision predicts the best scores for single-label classification tasks and detects out-of-scope (OOS) samples based on a threshold.

Variables:
  • thresh – The optimized threshold value for OOS detection.

  • name – Name of the predictor, defaults to “adaptive”.

  • n_classes – Number of classes determined during fitting.

Parameters:

search_space (list[float] | None)

Examples#

from autointent.modules import JinoosDecision
import numpy as np
scores = np.array([[0.2, 0.8], [0.6, 0.4], [0.1, 0.9]])
labels = [1, 0, 1]
search_space = [0.3, 0.5, 0.7]
predictor = JinoosDecision(search_space=search_space)
predictor.fit(scores, labels)
test_scores = np.array([[0.3, 0.7], [0.5, 0.5]])
predictions = predictor.predict(test_scores)
print(predictions)
[1 0]
thresh: float#
name = 'jinoos'#
n_classes: int#
search_space#
classmethod from_context(context, search_space=None)#

Initialize from context.

Parameters:
Return type:

JinoosDecision

fit(scores, labels, tags=None)#

Fit the model.

Parameters:
  • scores (numpy.typing.NDArray[Any]) – Scores to fit

  • labels (list[autointent.custom_types.LabelType]) – Labels to fit

  • tags (list[autointent.schemas.Tag] | None) – Tags to fit

Return type:

None

predict(scores)#

Predict the best score.

Parameters:

scores (numpy.typing.NDArray[Any]) – Scores to predict

Return type:

numpy.typing.NDArray[Any]

dump(path)#

Dump all data needed for inference.

Parameters:

path (str) – Path to dump

Return type:

None

load(path)#

Load data from dump.

Parameters:

path (str) – Path to load

Return type:

None

static jinoos_score(y_true, y_pred)#

Calculate Jinoos score.

\[\begin{split}\\frac{C_{in}}{N_{in}}+\\frac{C_{oos}}{N_{oos}}\end{split}\]
where $C_{in}$ is the number of correctly predicted in-domain labels

and $N_{in}$ is the total number of in-domain labels. The same for OOS samples

Parameters:
  • y_true (list[autointent.custom_types.LabelType] | numpy.typing.NDArray[Any]) – True labels

  • y_pred (list[autointent.custom_types.LabelType] | numpy.typing.NDArray[Any]) – Predicted labels

Return type:

float