# `CSMOTE`

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

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

Continuous Synthetic Minority Oversampling Technique.

Continuous Synthetic Minority Oversampling Technique (C-SMOTE) <sup>[1](#id2)</sup> is a
meta-strategy. This strategy saves all the minority samples in a window managed by
ADWIN. Meanwhile, a model is trained with the input data. When the minority sample
ratio falls below a certain threshold, an online version of SMOTE is applied. A
random minority sample is chosen from the window, and a new synthetic sample is
generated until the minority sample ratio is greater than or equal to the threshold.
The model is then trained with the newly generated samples.

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

* <a id='id2'>**[1]**</a> [Alessio Bernardo, Heitor Murilo Gomes, Jacob Montiel, Bernhard Pfahringer, Albert Bifet, Emanuele Della Valle. C-SMOTE: Continuous Synthetic Minority Oversampling for Evolving Data Streams. In BigData, IEEE, 2020.](https://ieeexplore.ieee.org/document/9377768)

#### \_\_init_\_(schema: [Schema](capymoa.stream.Schema.md#capymoa.stream.Schema) = None, random_seed: [int](https://docs.python.org/3/builtins/functions.html#int) = 0, base_learner='trees.HoeffdingTree', neighbors: [int](https://docs.python.org/3/builtins/functions.html#int) = 10, threshold: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.5, min_size_allowed: [int](https://docs.python.org/3/builtins/functions.html#int) = 100, disable_drift_detection: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/classifier/_csmote.py#L37)

Construct C-SMOTE.

* **Parameters:**
  * **schema** – The schema of the stream.
  * **random_seed** – The random seed passed to the MOA learner.
  * **base_learner** – The base learner to be trained. Default AdaptiveRandomForestClassifier.
  * **neighbors** – Number of neighbors for SMOTE.
  * **threshold** – Minority class samples threshold.
  * **min_size_allowed** – Minimum number of samples in the minority class for applying SMOTE.
  * **disable_drift_detection** – If set, disables ADWIN drift detector

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