# `LeveragingBagging`

### *class* capymoa.classifier.LeveragingBagging[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/classifier/_leveraging_bagging.py#L12)

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

Leveraging Bagging for evolving data streams using ADWIN.

Leveraging Bagging for evolving data streams using ADWIN <sup>[1](#id2)</sup> is a meta-strategy.

```pycon
>>> from capymoa.classifier import LeveragingBagging
>>> from capymoa.datasets import ElectricityTiny
>>> from capymoa.evaluation import prequential_evaluation
>>>
>>> stream = ElectricityTiny()
>>> classifier = LeveragingBagging(stream.get_schema())
>>> results = prequential_evaluation(stream, classifier, max_instances=1000)
>>> print(f"{results['cumulative'].accuracy():.1f}")
87.4
```

* <a id='id2'>**[1]**</a> [Albert Bifet, Geoffrey Holmes, Bernhard Pfahringer. Leveraging Bagging for Evolving Data Streams Machine Learning and Knowledge Discovery in Databases, European Conference, ECML PKDD}, 2010.](https://link.springer.com/chapter/10.1007/978-3-642-15880-3_15)

#### \_\_init_\_(schema=None, CLI=None, random_seed=1, base_learner=None, ensemble_size=100, minibatch_size=None, number_of_jobs=None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/classifier/_leveraging_bagging.py#L33)

Construct a Leveraging Bagging classifier.

* **Parameters:**
  * **schema** – The schema of the stream. If not provided, it will be inferred from the data.
  * **CLI** – Command Line Interface (CLI) options for configuring the ARF algorithm.
    If not provided, default options will be used.
  * **random_seed** – Seed for the random number generator.
  * **base_learner** – The base learner to use. If not provided, a default Hoeffding Tree is used.
  * **ensemble_size** – The number of trees in the ensemble.
  * **minibatch_size** – The number of instances that a learner must accumulate before training.
  * **number_of_jobs** – The number of parallel jobs to run during the execution of the algorithm.
    By default, the algorithm executes tasks sequentially (i.e., with number_of_jobs=1).
    Increasing the number_of_jobs can lead to faster execution on multi-core systems.
    However, setting it to a high value may consume more system resources and memory.
    This implementation focuses more on performance, therefore the predictive performance is modified.
    It’s recommended to experiment with different values to find the optimal setting based on
    the available hardware resources and the nature of the workload.

#### cli_help()[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_classifier.py#L111)

#### *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_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: [Instance](capymoa.core.Instance.md#capymoa.core.Instance)) → [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_classifier.py#L56)

Predict the label of an instance.

The base implementation calls [`predict_proba()`](#capymoa.classifier.LeveragingBagging.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) → [ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)[[tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[Any](https://docs.python.org/3/library/typing.html#typing.Any), ...], [dtype](https://numpy.org/doc/stable/reference/generated/numpy.dtype.html#numpy.dtype)[float64]] | [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_classifier.py#L117)

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/base/_classifier.py#L114)

Train the classifier with a labeled instance.

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

#### 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.
