|
16 | 16 | class STEPDConfig(BaseWindowConfig): |
17 | 17 | """STEPD (Statistical test of equal proportions) [nishida2007detecting]_ configuration. |
18 | 18 |
|
| 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 | +
|
19 | 26 | :References: |
20 | 27 |
|
21 | 28 | .. [nishida2007detecting] Nishida, Kyosuke, and Koichiro Yamauchi. |
22 | 29 | "Detecting concept drift using statistical testing." Discovery science. |
23 | 30 | Vol. 4755. 2007. |
24 | | - """ |
| 31 | + """ # noqa: E501 |
25 | 32 |
|
26 | | - def __init__( |
| 33 | + def __init__( # noqa: D107 |
27 | 34 | self, |
28 | 35 | alpha_d: float = 0.003, |
29 | 36 | alpha_w: float = 0.05, |
30 | 37 | min_num_instances: int = 30, |
31 | 38 | ) -> 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 | | - """ |
42 | 39 | super().__init__(min_num_instances=min_num_instances) |
43 | 40 | self.alpha_d = alpha_d |
44 | 41 | self.alpha_w = alpha_w |
@@ -91,30 +88,48 @@ def alpha_w(self, value: float) -> None: |
91 | 88 | class STEPD(BaseWindow): |
92 | 89 | """STEPD (Statistical test of equal proportions) [nishida2007detecting]_ detector. |
93 | 90 |
|
| 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 | +
|
94 | 96 | :References: |
95 | 97 |
|
96 | 98 | .. [nishida2007detecting] Nishida, Kyosuke, and Koichiro Yamauchi. |
97 | 99 | "Detecting concept drift using statistical testing." Discovery science. |
98 | 100 | 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 |
100 | 123 |
|
101 | 124 | config_type = STEPDConfig # type: ignore |
102 | 125 |
|
103 | | - def __init__( |
| 126 | + def __init__( # noqa: D107 |
104 | 127 | self, |
105 | 128 | config: Optional[STEPDConfig] = None, |
106 | 129 | callbacks: Optional[ |
107 | 130 | Union[BaseCallbackStreaming, List[BaseCallbackStreaming]] |
108 | 131 | ] = None, |
109 | 132 | ) -> 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 | | - """ |
118 | 133 | super().__init__( |
119 | 134 | config=config, |
120 | 135 | callbacks=callbacks, |
|
0 commit comments