# `HDDMWeighted`

### *class* capymoa.drift.detectors.HDDMWeighted[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/detectors/hddm_w.py#L8)

Bases: [`MOADriftDetector`](capymoa.drift.base_detector.MOADriftDetector.md#capymoa.drift.base_detector.MOADriftDetector)

Weighted Hoeffding’s bounds Drift Detector

Online and non-parametric drift detection methods based on Hoeffding’s bounds <sup>[1](#f1)</sup>.

```pycon
>>> import numpy as np
>>> from capymoa.drift.detectors import HDDMWeighted
>>> np.random.seed(0)
>>>
>>> detector = HDDMWeighted(lambda_=0.001)
>>>
>>> data_stream = np.random.randint(2, size=2000)
>>> for i in range(999, 2000):
...     data_stream[i] = np.random.randint(4, high=8)
>>>
>>> for i in range(2000):
...     detector.add_element(float(data_stream[i]))
...     if detector.detected_change():
...         print("Change detected in data: " + str(data_stream[i]) + " - at index: " + str(i))
Change detected in data: 6 - at index: 1234
```

* <a id='f1'>**[1]**</a> Frias-Blanco, Isvani, et al. “Online and non-parametric drift detection methods based on Hoeffding’s bounds.” IEEE Transactions on Knowledge and Data Engineering 27.3 (2014): 810-823.

#### \_\_init_\_(drift_confidence: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.001, warning_confidence: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.005, lambda_: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.05, test_type: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)['Two-sided', 'One-sided'] = 'Two-sided', CLI: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/detectors/hddm_w.py#L38)

* **Parameters:**
  * **drift_confidence** – Significance level for drift detection (p-value threshold).
  * **warning_confidence** – Significance level for warning detection (p-value threshold).
  * **lambda** – Forgetting factor (decay rate) for the weighted mean. A smaller
    value gives more weight to recent observations.
  * **test_type** – 

    The type of statistical hypothesis test to use.
    * `"Two-sided"` detects drift in both directions, i.e. both increases and
      decreases in the monitored weighted average. Use this when the direction of
      change is unknown.
    * `"One-sided"` only detects increases in the monitored weighted average
      (i.e. performance degradation). Use this when only positive drift is relevant.
  * **CLI** – (Advanced) Override the CLI arguments passed directly to the
    underlying MOA detector, bypassing all other parameters.

#### add_element(element: [float](https://docs.python.org/3/builtins/functions.html#float)) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/base_detector.py#L106)

Update the drift detector with a new input value.

* **Parameters:**
  **element** – A value to update the drift detector with. Usually,
  this is the prediction error of a model.

#### cli_help() → [str](https://docs.python.org/3/builtins/stdtypes.html#str)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/base_detector.py#L137)

#### detected_change() → [bool](https://docs.python.org/3/builtins/functions.html#bool)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/base_detector.py#L52)

Is the detector currently detecting a concept drift?

#### detected_warning() → [bool](https://docs.python.org/3/builtins/functions.html#bool)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/base_detector.py#L56)

Is the detector currently warning of an upcoming concept drift?

#### *classmethod* from_cli(cli: [str](https://docs.python.org/3/builtins/stdtypes.html#str)) → [MOADriftDetector](capymoa.drift.base_detector.MOADriftDetector.md#capymoa.drift.base_detector.MOADriftDetector)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/base_detector.py#L90)

Create a detector instance configured from a MOA CLI string.

* **Parameters:**
  **cli** – Command-line style options string for MOA detector hyper-parameters.
* **Returns:**
  A new detector instance initialized with `cli`.

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

#### reset(clean_history: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/base_detector.py#L121)

Reset the drift detector.

* **Parameters:**
  **clean_history** – Whether to reset detection history, defaults to False

#### REQUIRES_FIT *: [bool](https://docs.python.org/3/builtins/functions.html#bool)* *= False*

If `True`, this detector needs a reference distribution before
it can detect change. Concept drift detectors leave this as
`False` and only use [`add_element()`](#capymoa.drift.detectors.HDDMWeighted.add_element).

#### TEST_TYPES *= ('Two-sided', 'One-sided')*
