PageHinkley#
- class capymoa.drift.detectors.PageHinkley[source]#
Bases:
MOADriftDetectorPage-Hinkley Drift Detector
Example:#
>>> import numpy as np >>> from capymoa.drift.detectors import PageHinkley >>> np.random.seed(0) >>> >>> detector = PageHinkley() >>> >>> 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: 7 - at index: 1014 Change detected in data: 7 - at index: 1685
Reference:#
Page. 1954. Continuous Inspection Schemes. Biometrika 41, 1/2 (1954), 100-115.
- __init__( )[source]#
Create a Page-Hinkley drift detector.
- Parameters:
min_n_instances – Minimum number of instances to observe before change detection is enabled. Defaults to 30.
delta – Slack term subtracted at each update of the running statistic. Larger values make the detector less sensitive to small shifts. Defaults to 0.005.
lambda – Detection threshold for the Page-Hinkley statistic; once exceeded, a change is reported. Defaults to 50.0.
alpha – Forgetting factor applied to the previous statistic. Values closer to 1.0 retain longer history and typically react more slowly to abrupt changes. Defaults to 0.9999.
- 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.
- 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.