BanditClassifier#

class capymoa.automl.BanditClassifier[source]#

Bases: Classifier

Bandit-based model selection for streaming classification.

Each base classifier is associated with an arm of a multi-armed bandit. At each training step, the bandit policy selects which model to train (i.e., which arm to pull). The reward corresponds to the model’s performance on the current instance. The best-performing model is then used for prediction [1].

>>> from capymoa.datasets import ElectricityTiny
>>> from capymoa.classifier import HoeffdingTree
>>> from capymoa.automl import BanditClassifier, EpsilonGreedy
>>> stream = ElectricityTiny()
>>> schema = stream.get_schema()
>>> learner = BanditClassifier(
...     schema=schema,
...     base_classifiers=[HoeffdingTree],
...     policy=EpsilonGreedy(epsilon=0.1, burn_in=100)
... )
>>> instance = next(stream)
>>> learner.train(instance)

See also

EpsilonGreedy

__init__(
schema: Schema = None,
random_seed: int = 1,
base_classifiers: list = None,
config_file: str = None,
metric: str = 'accuracy',
policy: EpsilonGreedy = None,
verbose: bool = False,
)[source]#

Construct a Bandit-based model selector.

Parameters:
  • schema – The schema of the stream.

  • random_seed – Random seed used for initialization.

  • base_classifiers – List of base classifier classes to consider.

  • config_file – Path to a JSON configuration file with model hyperparameters.

  • metric – The metric used to evaluate model performance. Defaults to "accuracy".

  • policy – The bandit policy used to choose which model to train (e.g., EpsilonGreedy).

  • verbose – If True, print progress information during training.

get_model_info() Dict[str, Any][source]#

Get information about the current state of the classifier.

Returns:

Dictionary containing classifier information

predict(instance)[source]#

Predict the class label for the given instance using the best model.

predict_proba(instance)[source]#

Predict class probabilities for the given instance using the best model.

train(instance)[source]#

Train the selected model(s) on the given instance.

property best_model#

Return the current best model.

random_seed: int#

The random seed for reproducibility.

When implementing a classifier ensure random number generators are seeded.

schema: Schema#

The schema representing the instances.