Skip to content

Commit

Permalink
Bugfix for detecting change points based on MOA (#1613)
Browse files Browse the repository at this point in the history
* Bugfix based on MOA source code in the _detect_change method. The k index should increment from 0 to bucket.current_idx - 1. The previous code "for k in range(bucket.current_idx - 1):" only increment k to bucket.current_idx - 2 because of the range function.

* Bugfix based on MOA source code in the _detect_change method. The k index should increment from 0 to bucket.current_idx - 1. The previous code "for k in range(bucket.current_idx - 1):" only increment k to bucket.current_idx - 2 because of the range function.

* Tests updated due to bugfix on the ADWIN change detector - reported on issue #1614
  • Loading branch information
denisesato authored Sep 11, 2024
1 parent e3b2163 commit c6dab1b
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion river/drift/adwin_c.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ cdef class AdaptiveWindowing:
break
bucket = self.bucket_deque[idx]

for k in range(bucket.current_idx - 1):
for k in range(bucket.current_idx):
n2 = self._calculate_bucket_size(idx) # length of window 2
u2 = bucket.get_total_at(k) # total of window 2
# Warning: means are calculated inside the loop to get updated values.
Expand Down Expand Up @@ -307,6 +307,7 @@ cdef class AdaptiveWindowing:
+ (1.0 / (n1 - self.min_window_length + 1)))
epsilon = (sqrt(2 * m_recip * self.variance_in_window * delta_prime)
+ 2 / 3 * delta_prime * m_recip)

return fabs(delta_mean) > epsilon


Expand Down
2 changes: 1 addition & 1 deletion river/drift/test_drift_detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def test_adwin():
expected_indices = [1055]
expected_indices = [1023]
detected_indices = perform_test(drift.ADWIN(), data_stream_1)

assert detected_indices == expected_indices
Expand Down
2 changes: 1 addition & 1 deletion river/ensemble/streaming_random_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class SRPClassifier(BaseSRPEnsemble, base.Classifier):
>>> metric = metrics.Accuracy()
>>> evaluate.progressive_val_score(dataset, model, metric)
Accuracy: 71.97%
Accuracy: 72.17%
Notes
-----
Expand Down
4 changes: 2 additions & 2 deletions river/forest/adaptive_random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ class ARFClassifier(BaseForest, base.Classifier):
>>> metric = metrics.Accuracy()
>>> evaluate.progressive_val_score(dataset, model, metric)
Accuracy: 71.17%
Accuracy: 67.97%
The total number of warnings and drifts detected, respectively
>>> model.n_warnings_detected(), model.n_drifts_detected()
Expand Down Expand Up @@ -849,7 +849,7 @@ class ARFRegressor(BaseForest, base.Regressor):
>>> metric = metrics.MAE()
>>> evaluate.progressive_val_score(dataset, model, metric)
MAE: 0.788619
MAE: 0.772113
"""

Expand Down
2 changes: 1 addition & 1 deletion river/forest/online_extra_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ class OXTRegressor(ExtraTrees, base.Regressor):
>>> metric = metrics.RMSE()
>>> evaluate.progressive_val_score(dataset, model, metric)
RMSE: 3.127311
RMSE: 3.16212
References
----------
Expand Down
8 changes: 4 additions & 4 deletions river/imblearn/chebyshev.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ class ChebyshevOverSampler(base.Wrapper, base.Regressor):
... metrics.MAE(),
... print_every=500
... )
[500] MAE: 1.673902
[1,000] MAE: 1.743046
[1,001] MAE: 1.741335
MAE: 1.741335
[500] MAE: 1.629786
[1,000] MAE: 1.663799
[1,001] MAE: 1.66253
MAE: 1.66253
References
----------
Expand Down
2 changes: 1 addition & 1 deletion river/tree/hoeffding_adaptive_tree_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class HoeffdingAdaptiveTreeRegressor(HoeffdingTreeRegressor):
>>> metric = metrics.MAE()
>>> evaluate.progressive_val_score(dataset, model, metric)
MAE: 0.823026
MAE: 0.917576
"""

Expand Down

0 comments on commit c6dab1b

Please sign in to comment.