# `SuccessiveHalvingClassifier`

### *class* capymoa.automl.SuccessiveHalvingClassifier[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/automl/_successive_halving_classifier.py#L16)

Bases: [`Classifier`](capymoa.base.Classifier.md#capymoa.base.Classifier)

Successive Halving Classifier for model selection in streaming scenarios.

This method applies the principle of *Successive Halving* <sup>[1](#jamieson2016)</sup>
to incrementally allocate more computational budget to the most promising
models while discarding poorly performing ones. It progressively narrows
the pool of candidates as more data is observed, improving efficiency in
streaming model selection.

```pycon
>>> from capymoa.datasets import ElectricityTiny
>>> from capymoa.classifier import HoeffdingTree
>>> from capymoa.automl import SuccessiveHalvingClassifier
>>> stream = ElectricityTiny()
>>> schema = stream.get_schema()
>>> learner = SuccessiveHalvingClassifier(
...     schema=schema,
...     base_classifiers=[HoeffdingTree],
...     eta=2.0,
...     evaluation_metric="accuracy"
... )
>>> instance = next(stream)
>>> learner.train(instance)
```

#### SEE ALSO
[`BanditClassifier`](capymoa.automl.BanditClassifier.md#capymoa.automl.BanditClassifier)

* <a id='jamieson2016'>**[1]**</a> Jamieson, K. & Talwalkar, A. (2016, May). *Non-stochastic best arm identification and hyperparameter optimization.* In Artificial Intelligence and Statistics (pp. 240–248). PMLR. [https://proceedings.mlr.press/v51/jamieson16.html](https://proceedings.mlr.press/v51/jamieson16.html)

#### \_\_init_\_(schema: [Schema](capymoa.stream.Schema.md#capymoa.stream.Schema) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, random_seed: [int](https://docs.python.org/3/builtins/functions.html#int) = 1, base_classifiers: [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[type](https://docs.python.org/3/builtins/functions.html#type)[[Classifier](capymoa.base.Classifier.md#capymoa.base.Classifier)]] | [None](https://docs.python.org/3/builtins/constants.html#None) = None, config_file: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, max_instances: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, budget: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, eta: [float](https://docs.python.org/3/builtins/functions.html#float) = 2.0, min_models: [int](https://docs.python.org/3/builtins/functions.html#int) = 1, evaluation_metric: [str](https://docs.python.org/3/builtins/stdtypes.html#str) = 'accuracy', verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/automl/_successive_halving_classifier.py#L49)

Construct a Successive Halving Classifier.

* **Parameters:**
  * **schema** – The schema of the stream.
  * **random_seed** – Random seed used for reproducibility.
  * **base_classifiers** – List of base classifier classes to consider.
  * **config_file** – Path to a JSON configuration file with model hyperparameters.
  * **max_instances** – Maximum number of instances to process per model.
    If provided, the total budget is computed as `2 * n_models * max_instances / eta`.
  * **budget** – Total training budget (number of instances across all models).
    Ignored if `max_instances` is provided.
  * **eta** – Reduction factor controlling how many models advance to the next round.
  * **min_models** – Minimum number of models to maintain in successive rounds.
  * **evaluation_metric** – Metric used to evaluate models. Defaults to `"accuracy"`.
  * **verbose** – Whether to print progress information during training.

#### *classmethod* from_params(schema: [Any](https://docs.python.org/3/library/typing.html#typing.Any) = None, params: [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Any](https://docs.python.org/3/library/typing.html#typing.Any)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None, random_seed: [int](https://docs.python.org/3/builtins/functions.html#int) = 1) → [Any](https://docs.python.org/3/library/typing.html#typing.Any)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_learner_params.py#L170)

Construct an instance from parameters produced by `get_params`.

#### get_model_info() → [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Any](https://docs.python.org/3/library/typing.html#typing.Any)][[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/automl/_successive_halving_classifier.py#L307)

Get information about the current state of the classifier.

Returns:
: Dictionary containing classifier information

#### get_params() → [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Any](https://docs.python.org/3/library/typing.html#typing.Any)][[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_learner_params.py#L163)

Return the hyper-parameters captured from the constructor.

#### predict(instance)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/automl/_successive_halving_classifier.py#L280)

Predict the label of an instance.

The base implementation calls [`predict_proba()`](#capymoa.automl.SuccessiveHalvingClassifier.predict_proba) and returns the
label with the highest probability.

* **Parameters:**
  **instance** – The instance to predict the label for.
* **Returns:**
  The predicted label or `None` if the classifier is unable
  to make a prediction.

#### predict_proba(instance)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/automl/_successive_halving_classifier.py#L289)

Return probability estimates for each label.

* **Parameters:**
  **instance** – The instance to estimate the probabilities for.
* **Returns:**
  An array of probabilities for each label or `None` if the
  classifier is unable to make a prediction.

#### train(instance)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/automl/_successive_halving_classifier.py#L202)

Train the classifier with a labeled instance.

* **Parameters:**
  **instance** – The labeled instance to train the classifier with.

#### *property* best_model

Return the current best model.

#### random_seed *: [int](https://docs.python.org/3/builtins/functions.html#int)*

The random seed for reproducibility.

When implementing a classifier ensure random number generators are seeded.

#### schema *: [Schema](capymoa.stream.Schema.md#capymoa.stream.Schema)*

The schema representing the instances.
