From 4c3e9287af548863cd8033bd734af39b2e43bfae Mon Sep 17 00:00:00 2001 From: Matt Eding Date: Tue, 19 Nov 2019 20:07:51 -0800 Subject: [PATCH 1/3] add n_iter_ attr; fix spelling of my name --- doc/whats_new/v0.6.rst | 2 +- .../_prototype_selection/_edited_nearest_neighbours.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/whats_new/v0.6.rst b/doc/whats_new/v0.6.rst index 223f68551..bb6c97196 100644 --- a/doc/whats_new/v0.6.rst +++ b/doc/whats_new/v0.6.rst @@ -81,7 +81,7 @@ Enhancement :class:`imblearn.over_sampling.KMeansSMOTE`, :class:`imblearn.over_sampling.SMOTENC` is now vectorize with giving an additional speed-up when `X` in sparse. - :pr:`596` by :user:`Matt Edding `. + :pr:`596` by :user:`Matt Eding `. Deprecation ........... diff --git a/imblearn/under_sampling/_prototype_selection/_edited_nearest_neighbours.py b/imblearn/under_sampling/_prototype_selection/_edited_nearest_neighbours.py index 162287032..41d62c622 100644 --- a/imblearn/under_sampling/_prototype_selection/_edited_nearest_neighbours.py +++ b/imblearn/under_sampling/_prototype_selection/_edited_nearest_neighbours.py @@ -202,6 +202,11 @@ class RepeatedEditedNearestNeighbours(BaseCleaningSampler): .. versionadded:: 0.4 + n_iter_ : int + Number of iterations run. + + .. versionadded:: 0.6 + See Also -------- CondensedNearestNeighbour : Undersample by condensing samples. @@ -325,6 +330,7 @@ def _fit_resample(self, X, y): ] break + self.n_iter_ = n_iter + 1 X_resampled, y_resampled = X_, y_ return X_resampled, y_resampled From 8aa150ebd5105ada7296f3b1cc95921375169b63 Mon Sep 17 00:00:00 2001 From: Matt Eding Date: Wed, 20 Nov 2019 09:02:49 -0800 Subject: [PATCH 2/3] n_iter_ testing --- .../tests/test_repeated_edited_nearest_neighbours.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/imblearn/under_sampling/_prototype_selection/tests/test_repeated_edited_nearest_neighbours.py b/imblearn/under_sampling/_prototype_selection/tests/test_repeated_edited_nearest_neighbours.py index 432a57300..2b25106e7 100644 --- a/imblearn/under_sampling/_prototype_selection/tests/test_repeated_edited_nearest_neighbours.py +++ b/imblearn/under_sampling/_prototype_selection/tests/test_repeated_edited_nearest_neighbours.py @@ -182,6 +182,7 @@ def test_renn_fit_resample(): ) assert_array_equal(X_resampled, X_gt) assert_array_equal(y_resampled, y_gt) + assert 0 < renn.n_iter_ <= renn.max_iter def test_renn_fit_resample_mode_object(): @@ -266,6 +267,7 @@ def test_renn_fit_resample_mode_object(): ) assert_array_equal(X_resampled, X_gt) assert_array_equal(y_resampled, y_gt) + assert 0 < renn.n_iter_ <= renn.max_iter def test_renn_fit_resample_mode(): @@ -351,6 +353,7 @@ def test_renn_fit_resample_mode(): ) assert_array_equal(X_resampled, X_gt) assert_array_equal(y_resampled, y_gt) + assert 0 < renn.n_iter_ <= renn.max_iter def test_renn_not_good_object(): @@ -358,3 +361,9 @@ def test_renn_not_good_object(): renn = RepeatedEditedNearestNeighbours(n_neighbors=nn, kind_sel="mode") with pytest.raises(ValueError): renn.fit_resample(X, Y) + + +def test_renn_iter_attribute(): + renn = RepeatedEditedNearestNeighbours(max_iter=1) + renn.fit_resample(X, Y) + assert renn.n_iter_ == 1 From da71b3acd5fcacd7c1a6b17c3974300d48471812 Mon Sep 17 00:00:00 2001 From: Matt Eding Date: Wed, 20 Nov 2019 09:52:49 -0800 Subject: [PATCH 3/3] fix renn iter test --- .../test_repeated_edited_nearest_neighbours.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/imblearn/under_sampling/_prototype_selection/tests/test_repeated_edited_nearest_neighbours.py b/imblearn/under_sampling/_prototype_selection/tests/test_repeated_edited_nearest_neighbours.py index 2b25106e7..209ebb2b3 100644 --- a/imblearn/under_sampling/_prototype_selection/tests/test_repeated_edited_nearest_neighbours.py +++ b/imblearn/under_sampling/_prototype_selection/tests/test_repeated_edited_nearest_neighbours.py @@ -363,7 +363,14 @@ def test_renn_not_good_object(): renn.fit_resample(X, Y) -def test_renn_iter_attribute(): - renn = RepeatedEditedNearestNeighbours(max_iter=1) +@pytest.mark.parametrize( + "max_iter, n_iter", + [ + (2, 2), + (5, 3), + ], +) +def test_renn_iter_attribute(max_iter, n_iter): + renn = RepeatedEditedNearestNeighbours(max_iter=max_iter) renn.fit_resample(X, Y) - assert renn.n_iter_ == 1 + assert renn.n_iter_ == n_iter