DDM#

class capymoa.drift.detectors.DDM[source]#

Bases: MOADriftDetector

Drift-Detection-Method (DDM) Drift Detector

Example:#

>>> import numpy as np
>>> from capymoa.drift.detectors import DDM
>>> np.random.seed(0)
>>>
>>> detector = DDM()
>>>
>>> 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(data_stream[i])
...     if detector.detected_change():
...         print('Change detected in data: ' + str(data_stream[i]) + ' - at index: ' + str(i))
Change detected in data: 4 - at index: 1005

Reference:#

Gama, Joao, et al. “Learning with drift detection.” Advances in Artificial Intelligence–SBIA 2004: 17th Brazilian Symposium on Artificial Intelligence, Sao Luis, Maranhao, Brazil, September 29-Ocotber 1, 2004.

__init__(
min_n_instances: int = 30,
warning_level: float = 2.0,
out_control_level: float = 3.0,
)[source]#

Create a DDM drift detector.

Parameters:
  • min_n_instances – Minimum number of instances to observe before change detection is enabled. Defaults to 30.

  • warning_level – Multiplier applied to the minimum error estimate for entering the warning zone. Defaults to 2.0.

  • out_control_level – Multiplier applied to the minimum error estimate for reporting a concept change. Defaults to 3.0.

add_element(element: float) None[source]#

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[source]#
detected_change() bool[source]#

Is the detector currently detecting a concept drift?

detected_warning() bool[source]#

Is the detector currently warning of an upcoming concept drift?

classmethod from_cli(cli: str) MOADriftDetector[source]#

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.

get_params() Dict[str, Any][source]#

Get the hyper-parameters of the drift detector.

reset(clean_history: bool = False) None[source]#

Reset the drift detector.

Parameters:

clean_history – Whether to reset detection history, defaults to False