Skip to content

Commit 32f9bd0

Browse files
Add STEPD API example
1 parent 5f27960 commit 32f9bd0

File tree

1 file changed

+37
-22
lines changed
  • frouros/detectors/concept_drift/streaming/window_based

1 file changed

+37
-22
lines changed

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

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,26 @@
1616
class STEPDConfig(BaseWindowConfig):
1717
"""STEPD (Statistical test of equal proportions) [nishida2007detecting]_ configuration.
1818
19+
:param alpha_d: significance value for overall, defaults to 0.003
20+
:type alpha_d: float
21+
:param alpha_w: significance value for last, defaults to 0.05
22+
:type alpha_w: float
23+
:param min_num_instances: minimum numbers of instances to start looking for changes, defaults to 30
24+
:type min_num_instances: int
25+
1926
:References:
2027
2128
.. [nishida2007detecting] Nishida, Kyosuke, and Koichiro Yamauchi.
2229
"Detecting concept drift using statistical testing." Discovery science.
2330
Vol. 4755. 2007.
24-
"""
31+
""" # noqa: E501
2532

26-
def __init__(
33+
def __init__( # noqa: D107
2734
self,
2835
alpha_d: float = 0.003,
2936
alpha_w: float = 0.05,
3037
min_num_instances: int = 30,
3138
) -> None:
32-
"""Init method.
33-
34-
:param alpha_d: significance value for overall
35-
:type alpha_d: float
36-
:param alpha_w: significance value for last
37-
:type alpha_w: float
38-
:param min_num_instances: minimum numbers of instances
39-
to start looking for changes
40-
:type min_num_instances: int
41-
"""
4239
super().__init__(min_num_instances=min_num_instances)
4340
self.alpha_d = alpha_d
4441
self.alpha_w = alpha_w
@@ -91,30 +88,48 @@ def alpha_w(self, value: float) -> None:
9188
class STEPD(BaseWindow):
9289
"""STEPD (Statistical test of equal proportions) [nishida2007detecting]_ detector.
9390
91+
:param config: configuration object of the detector, defaults to None. If None, the default configuration of :class:`STEPDConfig` is used.
92+
:type config: Optional[STEPDConfig]
93+
:param callbacks: callbacks, defaults to None
94+
:type callbacks: Optional[Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]]
95+
9496
:References:
9597
9698
.. [nishida2007detecting] Nishida, Kyosuke, and Koichiro Yamauchi.
9799
"Detecting concept drift using statistical testing." Discovery science.
98100
Vol. 4755. 2007.
99-
"""
101+
102+
:Example:
103+
104+
>>> from frouros.detectors.concept_drift import STEPD, STEPDConfig
105+
>>> import numpy as np
106+
>>> np.random.seed(seed=31)
107+
>>> dist_a = np.random.binomial(n=1, p=0.8, size=1000)
108+
>>> dist_b = np.random.binomial(n=1, p=0.5, size=1000)
109+
>>> stream = np.concatenate((dist_a, dist_b))
110+
>>> detector = STEPD(config=STEPDConfig(alpha_d=0.001, alpha_w=0.005))
111+
>>> for i, value in enumerate(stream):
112+
... _ = detector.update(value=value)
113+
... if detector.drift:
114+
... print(f"Change detected at index {i}")
115+
... break
116+
... if detector.warning:
117+
... print(f"Warning detected at index {i}")
118+
Warning detected at index 640
119+
Warning detected at index 641
120+
Warning detected at index 1023
121+
Change detected at index 1024
122+
""" # noqa: E501
100123

101124
config_type = STEPDConfig # type: ignore
102125

103-
def __init__(
126+
def __init__( # noqa: D107
104127
self,
105128
config: Optional[STEPDConfig] = None,
106129
callbacks: Optional[
107130
Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]
108131
] = None,
109132
) -> None:
110-
"""Init method.
111-
112-
:param config: configuration parameters
113-
:type config: Optional[STEPDConfig]
114-
:param callbacks: callbacks
115-
:type callbacks: Optional[Union[BaseCallbackStreaming,
116-
List[BaseCallbackStreaming]]]
117-
"""
118133
super().__init__(
119134
config=config,
120135
callbacks=callbacks,

0 commit comments

Comments
 (0)