# `DynamicEnsembleMemberSelection`

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

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

Dynamic Ensemble Member Selection (DEMS).

Dynamic Ensemble Member Selection (DEMS) <sup>[1](#id2)</sup> dynamically selects a subset of ensemble members based on their estimated performance and tree-level information.
Only SRP and ARF are included here because of the performance significance.

```pycon
>>> from capymoa.classifier import DynamicEnsembleMemberSelection
>>> from capymoa.datasets import ElectricityTiny
>>> from capymoa.evaluation import prequential_evaluation
>>>
>>> stream = ElectricityTiny()
>>> classifier = DynamicEnsembleMemberSelection(stream.get_schema())
>>> results = prequential_evaluation(stream, classifier, max_instances=1000)
>>> print(f"{results.accuracy():.1f}")
90.6
```

* <a id='id2'>**[1]**</a> [Dynamic Ensemble Member Selection for Data Stream Classification. Yibin Sun, Bernhard Pfahringer, Heitor Murilo Gomes, Albert Bifet. ACM Conference on Information and Knowledge Management (CIKM), 2025.](https://doi.org/10.1145/3746252.3761072)

#### \_\_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) = 0, ensemble_class: [str](https://docs.python.org/3/builtins/stdtypes.html#str) = 'StreamingRandomPatches', base_learner: [str](https://docs.python.org/3/builtins/stdtypes.html#str) = 'trees.HoeffdingTree -g 50 -c 0.01', tree_learner: [str](https://docs.python.org/3/builtins/stdtypes.html#str) = 'ARFHoeffdingTree -e 2000000 -g 50 -c 0.01', ensemble_size: [int](https://docs.python.org/3/builtins/functions.html#int) = 100, max_features=0.6, training_method: [str](https://docs.python.org/3/builtins/stdtypes.html#str) = 'RandomPatches', lambda_param: [float](https://docs.python.org/3/builtins/functions.html#float) = 6.0, number_of_jobs: [int](https://docs.python.org/3/builtins/functions.html#int) = 1, drift_detection_method: [str](https://docs.python.org/3/builtins/stdtypes.html#str) = 'ADWINChangeDetector -a 1.0E-5', warning_detection_method: [str](https://docs.python.org/3/builtins/stdtypes.html#str) = 'ADWINChangeDetector -a 1.0E-4', disable_weighted_vote: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, disable_drift_detection: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, disable_background_learner: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, k_value: [int](https://docs.python.org/3/builtins/functions.html#int) = 5, disable_self_optimising: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/classifier/_dems.py#L32)

Dynamic Ensemble Member Selection (DEMS) Classifier.

* **Parameters:**
  * **ensemble_class** – which ensemble to use (“StreamingRandomPatches” or “AdaptiveRandomForest”).
  * **base_learner** – base classifier (used by SRP).
  * **tree_learner** – ARF tree learner (only used by ARF, cannot be changed).
  * **ensemble_size** – number of ensemble members.
  * **max_features** – subspace size configuration, similar to SRP:
    float in [0, 1]: percentage of features (e.g. 0.6 = 60%).
    int: exact number of features.
    “sqrt”: use sqrt(M)+1.
    None: default (60%).
  * **training_method** – “RandomSubspaces”, “Resampling”, or “RandomPatches” (SRP).
  * **lambda_param** – Poisson lambda for bagging.
  * **number_of_jobs** – number of parallel jobs for ARF (-1 = as many as possible).
  * **drift_detection_method** – MOA CLI string for drift detector.
  * **warning_detection_method** – MOA CLI string for warning detector.
  * **disable_weighted_vote** – if True, disables accuracy-weighted voting.
  * **disable_drift_detection** – if True, turns off drift detectors (and bkg learners).
  * **disable_background_learner** – if True, turns off background learners.
  * **k_value** – fixed K for DEMS when self-optimising is disabled.
  * **disable_self_optimising** – if True, use the fixed k_value instead of self-optimising.

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