Skip to content

Commit e7af505

Browse files
Add ADWIN API example
1 parent d30ad32 commit e7af505

File tree

1 file changed

+36
-28
lines changed
  • frouros/detectors/concept_drift/streaming/window_based

1 file changed

+36
-28
lines changed

frouros/detectors/concept_drift/streaming/window_based/adwin.py

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -155,38 +155,33 @@ def compress(self, num_items_deleted: int) -> None:
155155
class ADWINConfig(BaseWindowConfig):
156156
"""ADWIN (ADaptive WINdowing) [bifet2007learning]_ configuration.
157157
158+
:param clock: clock value, default to 32
159+
:type clock: int
160+
:param delta: confidence value, default to 0.002
161+
:type delta: float
162+
:param m: controls the amount of memory used and the closeness of the cutpoints checked, default to 5
163+
:type m: int
164+
:param min_window_size: minimum numbers of instances per window to start looking for changes, default to 5
165+
:type min_window_size: int
166+
:param min_num_instances: minimum numbers of instances to start looking for changes, default to 10
167+
:type min_num_instances: int
168+
158169
:References:
159170
160171
.. [bifet2007learning] Bifet, Albert, and Ricard Gavalda.
161172
"Learning from time-changing data with adaptive windowing."
162173
Proceedings of the 2007 SIAM international conference on data mining.
163174
Society for Industrial and Applied Mathematics, 2007.
164-
"""
175+
""" # noqa: E501
165176

166-
def __init__(
177+
def __init__( # noqa: D107
167178
self,
168179
clock: int = 32,
169180
delta: float = 0.002,
170181
m: int = 5,
171182
min_window_size: int = 5,
172183
min_num_instances: int = 10,
173184
) -> None:
174-
"""Init method.
175-
176-
:param clock: clock value
177-
:type clock: int
178-
:param delta: confidence value
179-
:type delta: float
180-
:param m: controls the amount of memory used and
181-
the closeness of the cutpoints checked
182-
:type m: int
183-
:param min_window_size: minimum numbers of instances
184-
per window to start looking for changes
185-
:type min_window_size: int
186-
:param min_num_instances: minimum numbers of instances
187-
to start looking for changes
188-
:type min_num_instances: int
189-
"""
190185
super().__init__(min_num_instances=min_num_instances)
191186
self.clock = clock
192187
self.delta = delta
@@ -282,31 +277,44 @@ def min_window_size(self, value: int) -> None:
282277
class ADWIN(BaseWindow):
283278
"""ADWIN (ADaptive WINdowing) [bifet2007learning]_ detector.
284279
280+
:param config: configuration object of the detector, defaults to None. If None, the default configuration of :class:`ADWINConfig` is used.
281+
:type config: Optional[ADWINConfig]
282+
:param callbacks: callbacks, defaults to None
283+
:type callbacks: Optional[Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]]
284+
285285
:References:
286286
287287
.. [bifet2007learning] Bifet, Albert, and Ricard Gavalda.
288288
"Learning from time-changing data with adaptive windowing."
289289
Proceedings of the 2007 SIAM international conference on data mining.
290290
Society for Industrial and Applied Mathematics, 2007.
291-
"""
291+
292+
:Example:
293+
294+
>>> from frouros.detectors.concept_drift import ADWIN
295+
>>> import numpy as np
296+
>>> np.random.seed(seed=31)
297+
>>> dist_a = np.random.normal(loc=0.2, scale=0.01, size=1000)
298+
>>> dist_b = np.random.normal(loc=0.8, scale=0.04, size=1000)
299+
>>> stream = np.concatenate((dist_a, dist_b))
300+
>>> detector = ADWIN()
301+
>>> for i, value in enumerate(stream):
302+
... _ = detector.update(value=value)
303+
... if detector.drift:
304+
... print(f"Change detected at index {i}")
305+
... break
306+
Change detected at index 1055
307+
""" # noqa: E501
292308

293309
config_type = ADWINConfig
294310

295-
def __init__(
311+
def __init__( # noqa: D107
296312
self,
297313
config: Optional[ADWINConfig] = None,
298314
callbacks: Optional[
299315
Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]
300316
] = None,
301317
) -> None:
302-
"""Init method.
303-
304-
:param config: configuration parameters
305-
:type config: Optional[ADWINConfig]
306-
:param callbacks: callbacks
307-
:type callbacks: Optional[Union[BaseCallbackStreaming,
308-
List[BaseCallbackStreaming]]]
309-
"""
310318
super().__init__(
311319
config=config,
312320
callbacks=callbacks,

0 commit comments

Comments
 (0)