Skip to content

[MRG] ENH: RepeatedENN n_iter_ Attribute #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/whats_new/v0.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <MattEding>`.
:pr:`596` by :user:`Matt Eding <MattEding>`.

Deprecation
...........
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -351,10 +353,24 @@ 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():
nn = "rnd"
renn = RepeatedEditedNearestNeighbours(n_neighbors=nn, kind_sel="mode")
with pytest.raises(ValueError):
renn.fit_resample(X, Y)


@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_ == n_iter