autointent.modules.decision.AdaptiveDecision#

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

Bases: autointent.modules.abc.DecisionModule

Decision for multi-label classification using adaptive thresholds.

The AdaptiveDecision calculates optimal thresholds based on the given scores and labels, ensuring the best performance on multi-label data.

Variables:
  • metadata_dict_name – Filename for saving metadata to disk.

  • n_classes – Number of classes in the dataset.

  • _r – Scaling factor for thresholds.

  • tags – List of Tag objects for mutually exclusive classes.

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

Parameters:

search_space (list[float] | None)

Examples#

from autointent.modules.decision import AdaptiveDecision
import numpy as np
scores = np.array([[0.8, 0.1, 0.4], [0.2, 0.9, 0.5]])
labels = [[1, 0, 0], [0, 1, 0]]
predictor = AdaptiveDecision()
predictor.fit(scores, labels)
decisions = predictor.predict(scores)
print(decisions)
[[1 0 0]
 [0 1 0]]
metadata_dict_name = 'metadata.json'#
n_classes: int#
tags: list[autointent.schemas.Tag] | None#
name = 'adaptive'#
search_space = None#
classmethod from_context(context, search_space=None)#

Create an AdaptiveDecision instance using a Context object.

Parameters:
  • context (autointent.Context) – Context containing configurations and utilities.

  • search_space (list[float] | None) – List of threshold scaling factors, or None for default.

Returns:

Initialized AdaptiveDecision instance.

Return type:

AdaptiveDecision

fit(scores, labels, tags=None)#

Fit the predictor by optimizing the threshold scaling factor.

Parameters:
  • scores (numpy.typing.NDArray[Any]) – Array of shape (n_samples, n_classes) with predicted scores.

  • labels (list[autointent.custom_types.LabelType]) – List of true multi-label targets.

  • tags (list[autointent.schemas.Tag] | None) – List of Tag objects for mutually exclusive classes, or None.

Raises:

WrongClassificationError – If used on non-multi-label data.

Return type:

None

predict(scores)#

Predict labels for the given scores.

Parameters:

scores (numpy.typing.NDArray[Any]) – Array of shape (n_samples, n_classes) with predicted scores.

Returns:

Array of shape (n_samples, n_classes) with predicted binary labels.

Raises:

InvalidNumClassesError – If the number of classes does not match the trained predictor.

Return type:

numpy.typing.NDArray[Any]

dump(path)#

Save the predictor’s metadata to disk.

Parameters:

path (str) – Path to the directory where metadata will be saved.

Return type:

None

load(path)#

Load the predictor’s metadata from disk.

Parameters:

path (str) – Path to the directory containing saved metadata.

Return type:

None