OPTWIN#

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

Bases: BaseDriftDetector

Optimal Window Concept Drift Detector

Drift Identification with Optimal Sub-Windows (OPTWIN) [1] is a drift detection method.

>>> import numpy as np
>>> from capymoa.drift.detectors import OPTWIN
>>> np.random.seed(0)
>>>
>>> detector = OPTWIN(rigor=0.1, drift_confidence=0.9)
>>>
>>> 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: 1164
__init__(
rigor: float = 0.5,
drift_confidence: float = 0.999,
warning_confidence: float = 0.9,
empty_w: bool = True,
w_length_max: int = 1_000,
w_length_min: int = 30,
minimum_noise: float = 1e-6,
)[source]#

Initialize the OPTWIN drift detector.

Parameters:
  • rigor – Rigorousness of drift identification

  • drift_confidence – Confidence value chosen by user

  • warning_confidence – Confidence value for warning zone

  • empty_w – Empty window when drift is detected

  • w_length_max – Maximum window size. 25000 is recommended but slows down initialization as it pre-computes optimal cuts for all window sizes up to w_length_max.

  • w_length_min – Minimum window size

  • minimum_noise – Noise to be added to stdev in case it is 0

add_element(element: float) None[source]#

Add the new element and perform change detection

Parameters:

element – The new observation

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?

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

Get the hyper-parameters of the OPTWIN drift detector.

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

Reset the drift detector.

Parameters:

clean_history – Whether to reset detection history, defaults to False