STEPD#

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

Bases: MOADriftDetector

Statistical Test of Equal Proportions Drift Detector

Example:#

>>> import numpy as np
>>> from capymoa.drift.detectors import STEPD
>>> np.random.seed(0)
>>>
>>> detector = STEPD()
>>>
>>> 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: 6 - at index: 1001

Reference:#

Nishida, Kyosuke, and Koichiro Yamauchi. “Detecting concept drift using statistical testing.” International conference on discovery science. Berlin, Heidelberg: Springer Berlin Heidelberg, 2007.

__init__(
window_size: int = 30,
alpha_drift: float = 0.003,
alpha_warning: float = 0.05,
)[source]#

Create a STEPD drift detector.

Parameters:
  • window_size – Size of the recent window used by STEPD to compare recent and older prediction proportions. Larger values smooth short-term noise but usually react more slowly. Defaults to 30.

  • alpha_drift – Significance level for declaring drift. Smaller values make drift alarms more conservative; larger values make them easier to trigger. Defaults to 0.003.

  • alpha_warning – Significance level for entering warning state. This is typically less strict than alpha_drift so warnings can appear before full drift. Defaults to 0.05.

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.

classmethod from_params(
schema: Any = None,
params: dict[str, Any] | None = None,
random_seed: int = 1,
) → Any[source]#

Construct an instance from parameters produced by get_params.

get_params() → dict[str, Any][source]#

Return the hyper-parameters captured from the constructor.

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

Reset the drift detector.

Parameters:

clean_history – Whether to reset detection history, defaults to False

REQUIRES_FIT: 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().