Skip to content

Commit 879da06

Browse files
authored
MAINT Housekeeping remove deprecated parameters (#332)
* MAINT Housekeeping remove deprecated parameters * TST solve error clustercentroids * TST remove useless tests
1 parent 3e0f3cc commit 879da06

29 files changed

+114
-1119
lines changed

doc/whats_new.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
Release history
55
===============
66

7+
.. include:: whats_new/v0.0.4.rst
8+
79
.. include:: whats_new/v0.0.3.rst
8-
10+
911
.. include:: whats_new/v0.0.2.rst
1012

1113
.. include:: whats_new/v0.0.1.rst

doc/whats_new/v0.0.4.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. _changes_0_3:
2+
3+
Version 0.4 (under development)
4+
===============================
5+
6+
Changelog
7+
---------
8+
9+
Maintenance
10+
...........
11+
12+
- Remove deprecated parameters in 0.2 - :issue:`331` by :user:`Guillaume
13+
Lemaitre <glemaitre>`.

imblearn/combine/smote_enn.py

Lines changed: 3 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from __future__ import division
88

99
import logging
10-
import warnings
1110

1211
from sklearn.utils import check_X_y
1312

@@ -54,82 +53,6 @@ class SMOTEENN(SamplerMixin):
5453
a :class:`imblearn.over_sampling.SMOTE` object with default parameters
5554
will be given.
5655
57-
enn : object, optional (default=EditedNearestNeighbours())
58-
The :class:`imblearn.under_sampling.EditedNearestNeighbours` object to
59-
use. If not given, an
60-
:class:`imblearn.under_sampling.EditedNearestNeighbours` object with
61-
default parameters will be given.
62-
63-
k : int, optional (default=None)
64-
Number of nearest neighbours to used to construct synthetic
65-
samples.
66-
67-
.. deprecated:: 0.2
68-
`k` is deprecated from 0.2 and will be replaced in 0.4
69-
Give directly a :class:`imblearn.over_sampling.SMOTE` object.
70-
71-
m : int, optional (default=None)
72-
Number of nearest neighbours to use to determine if a minority
73-
sample is in danger.
74-
75-
.. deprecated:: 0.2
76-
`m` is deprecated from 0.2 and will be replaced in 0.4
77-
Give directly a :class:`imblearn.over_sampling.SMOTE` object.
78-
79-
out_step : float, optional (default=None)
80-
Step size when extrapolating.
81-
82-
.. deprecated:: 0.2
83-
``out_step`` is deprecated from 0.2 and will be replaced in 0.4
84-
Give directly a :class:`imblearn.over_sampling.SMOTE` object.
85-
86-
kind_smote : str, optional (default=None)
87-
The type of SMOTE algorithm to use one of the following
88-
options: ``'regular'``, ``'borderline1'``, ``'borderline2'``,
89-
``'svm'``.
90-
91-
.. deprecated:: 0.2
92-
`kind_smote` is deprecated from 0.2 and will be replaced in 0.4
93-
Give directly a :class:`imblearn.over_sampling.SMOTE` object.
94-
95-
size_ngh : int, optional (default=None)
96-
Size of the neighbourhood to consider to compute the average
97-
distance to the minority point samples.
98-
99-
.. deprecated:: 0.2
100-
size_ngh is deprecated from 0.2 and will be replaced in 0.4
101-
Use ``n_neighbors`` instead.
102-
103-
n_neighbors : int, optional (default=None)
104-
Size of the neighbourhood to consider to compute the average
105-
distance to the minority point samples.
106-
107-
.. deprecated:: 0.2
108-
`n_neighbors` is deprecated from 0.2 and will be replaced in 0.4
109-
Give directly a
110-
:class:`imblearn.under_sampling.EditedNearestNeighbours` object.
111-
112-
kind_sel : str, optional (default=None)
113-
Strategy to use in order to exclude samples.
114-
115-
- If ``'all'``, all neighbours will have to agree with the samples of
116-
interest to not be excluded.
117-
- If ``'mode'``, the majority vote of the neighbours will be used in
118-
order to exclude a sample.
119-
120-
.. deprecated:: 0.2
121-
``kind_sel`` is deprecated from 0.2 and will be replaced in 0.4 Give
122-
directly a :class:`imblearn.under_sampling.EditedNearestNeighbours`
123-
object.
124-
125-
n_jobs : int, optional (default=None)
126-
The number of threads to open if possible.
127-
128-
.. deprecated:: 0.2
129-
`n_jobs` is deprecated from 0.2 and will be replaced in 0.4 Give
130-
directly a :class:`imblearn.over_sampling.SMOTE` and
131-
:class:`imblearn.under_sampling.EditedNearestNeighbours` object.
132-
13356
Notes
13457
-----
13558
The method is presented in [1]_.
@@ -173,65 +96,17 @@ def __init__(self,
17396
ratio='auto',
17497
random_state=None,
17598
smote=None,
176-
enn=None,
177-
k=None,
178-
m=None,
179-
out_step=None,
180-
kind_smote=None,
181-
size_ngh=None,
182-
n_neighbors=None,
183-
kind_enn=None,
184-
n_jobs=None):
99+
enn=None):
185100
super(SMOTEENN, self).__init__()
186101
self.ratio = ratio
187102
self.random_state = random_state
188103
self.smote = smote
189104
self.enn = enn
190-
self.k = k
191-
self.m = m
192-
self.out_step = out_step
193-
self.kind_smote = kind_smote
194-
self.size_ngh = size_ngh
195-
self.n_neighbors = n_neighbors
196-
self.kind_enn = kind_enn
197-
self.n_jobs = n_jobs
198105
self.logger = logging.getLogger(__name__)
199106

200107
def _validate_estimator(self):
201108
"Private function to validate SMOTE and ENN objects"
202-
203-
# Check any parameters for SMOTE was provided
204-
# Anounce deprecation
205-
if (self.k is not None or self.m is not None or
206-
self.out_step is not None or self.kind_smote is not None or
207-
self.n_jobs is not None):
208-
# We need to list each parameter and decide if we affect a default
209-
# value or not
210-
if self.k is None:
211-
self.k = 5
212-
if self.m is None:
213-
self.m = 10
214-
if self.out_step is None:
215-
self.out_step = 0.5
216-
if self.kind_smote is None:
217-
self.kind_smote = 'regular'
218-
if self.n_jobs is None:
219-
smote_jobs = 1
220-
else:
221-
smote_jobs = self.n_jobs
222-
warnings.warn('Parameters initialization will be replaced in'
223-
' version 0.4. Use a SMOTE object instead.',
224-
DeprecationWarning)
225-
self.smote_ = SMOTE(
226-
ratio=self.ratio,
227-
random_state=self.random_state,
228-
k=self.k,
229-
m=self.m,
230-
out_step=self.out_step,
231-
kind=self.kind_smote,
232-
n_jobs=smote_jobs)
233-
# If an object was given, affect
234-
elif self.smote is not None:
109+
if self.smote is not None:
235110
if isinstance(self.smote, SMOTE):
236111
self.smote_ = self.smote
237112
else:
@@ -242,30 +117,7 @@ def _validate_estimator(self):
242117
self.smote_ = SMOTE(
243118
ratio=self.ratio, random_state=self.random_state)
244119

245-
# Check any parameters for ENN was provided
246-
# Anounce deprecation
247-
if (self.size_ngh is not None or self.n_neighbors is not None or
248-
self.kind_enn is not None or self.n_jobs is not None):
249-
warnings.warn('Parameters initialization will be replaced in'
250-
' version 0.4. Use a ENN object instead.',
251-
DeprecationWarning)
252-
# We need to list each parameter and decide if we affect a default
253-
# value or not
254-
if self.n_neighbors is None:
255-
self.n_neighbors = 3
256-
if self.kind_enn is None:
257-
self.kind_enn = 'all'
258-
if self.n_jobs is None:
259-
self.n_jobs = 1
260-
self.enn_ = EditedNearestNeighbours(
261-
ratio='all',
262-
random_state=self.random_state,
263-
size_ngh=self.size_ngh,
264-
n_neighbors=self.n_neighbors,
265-
kind_sel=self.kind_enn,
266-
n_jobs=self.n_jobs)
267-
# If an object was given, affect
268-
elif self.enn is not None:
120+
if self.enn is not None:
269121
if isinstance(self.enn, EditedNearestNeighbours):
270122
self.enn_ = self.enn
271123
else:

imblearn/combine/smote_tomek.py

Lines changed: 3 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -61,45 +61,6 @@ class SMOTETomek(SamplerMixin):
6161
a :class:`imblearn.under_sampling.Tomek` object with default parameters
6262
will be given.
6363
64-
k : int, optional (default=None)
65-
Number of nearest neighbours to used to construct synthetic
66-
samples.
67-
68-
.. deprecated:: 0.2
69-
``k`` is deprecated from 0.2 and will be replaced in 0.4
70-
Give directly a :class:`imblearn.over_sampling.SMOTE` object.
71-
72-
m : int, optional (default=None)
73-
Number of nearest neighbours to use to determine if a minority
74-
sample is in danger.
75-
76-
.. deprecated:: 0.2
77-
``m`` is deprecated from 0.2 and will be replaced in 0.4
78-
Give directly a :class:`imblearn.over_sampling.SMOTE` object.
79-
80-
out_step : float, optional (default=None)
81-
Step size when extrapolating.
82-
83-
.. deprecated:: 0.2
84-
``out_step`` is deprecated from 0.2 and will be replaced in 0.4
85-
Give directly a :class:`imblearn.over_sampling.SMOTE` object.
86-
87-
kind_smote : str, optional (default=None)
88-
The type of SMOTE algorithm to use one of the following
89-
options: ``'regular'``, ``'borderline1'``, ``'borderline2'``,
90-
``'svm'``.
91-
92-
.. deprecated:: 0.2
93-
``kind_smote`` is deprecated from 0.2 and will be replaced in 0.4
94-
Give directly a :class:`imblearn.over_sampling.SMOTE` object.
95-
96-
n_jobs : int, optional (default=None)
97-
The number of threads to open if possible.
98-
99-
.. deprecated:: 0.2
100-
``n_jobs`` is deprecated from 0.2 and will be replaced in 0.4
101-
Give directly a :class:`imblearn.over_sampling.SMOTE` object.
102-
10364
Notes
10465
-----
10566
The methos is presented in [1]_.
@@ -143,59 +104,18 @@ def __init__(self,
143104
ratio='auto',
144105
random_state=None,
145106
smote=None,
146-
tomek=None,
147-
k=None,
148-
m=None,
149-
out_step=None,
150-
kind_smote=None,
151-
n_jobs=None):
107+
tomek=None):
152108
super(SMOTETomek, self).__init__()
153109
self.ratio = ratio
154110
self.random_state = random_state
155111
self.smote = smote
156112
self.tomek = tomek
157-
self.k = k
158-
self.m = m
159-
self.out_step = out_step
160-
self.kind_smote = kind_smote
161-
self.n_jobs = n_jobs
162113
self.logger = logging.getLogger(__name__)
163114

164115
def _validate_estimator(self):
165116
"Private function to validate SMOTE and ENN objects"
166117

167-
# Check any parameters for SMOTE was provided
168-
# Anounce deprecation
169-
if (self.k is not None or self.m is not None or
170-
self.out_step is not None or self.kind_smote is not None or
171-
self.n_jobs is not None):
172-
warnings.warn('Parameters initialization will be replaced in'
173-
' version 0.4. Use a SMOTE object instead.',
174-
DeprecationWarning)
175-
# We need to list each parameter and decide if we affect a default
176-
# value or not
177-
if self.k is None:
178-
self.k = 5
179-
if self.m is None:
180-
self.m = 10
181-
if self.out_step is None:
182-
self.out_step = 0.5
183-
if self.kind_smote is None:
184-
self.kind_smote = 'regular'
185-
if self.n_jobs is None:
186-
smote_jobs = 1
187-
else:
188-
smote_jobs = self.n_jobs
189-
self.smote_ = SMOTE(
190-
ratio=self.ratio,
191-
random_state=self.random_state,
192-
k=self.k,
193-
m=self.m,
194-
out_step=self.out_step,
195-
kind=self.kind_smote,
196-
n_jobs=smote_jobs)
197-
# If an object was given, affect
198-
elif self.smote is not None:
118+
if self.smote is not None:
199119
if isinstance(self.smote, SMOTE):
200120
self.smote_ = self.smote
201121
else:
@@ -206,17 +126,7 @@ def _validate_estimator(self):
206126
self.smote_ = SMOTE(
207127
ratio=self.ratio, random_state=self.random_state)
208128

209-
# Check any parameters for ENN was provided
210-
# Anounce deprecation
211-
if self.n_jobs is not None:
212-
warnings.warn('Parameters initialization will be replaced in'
213-
' version 0.4. Use a ENN object instead.',
214-
DeprecationWarning)
215-
self.tomek_ = TomekLinks(ratio='all',
216-
random_state=self.random_state,
217-
n_jobs=self.n_jobs)
218-
# If an object was given, affect
219-
elif self.tomek is not None:
129+
if self.tomek is not None:
220130
if isinstance(self.tomek, TomekLinks):
221131
self.tomek_ = self.tomek
222132
else:

imblearn/combine/tests/test_smote_enn.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,27 @@ def test_sample_regular():
4545
assert_array_equal(y_resampled, y_gt)
4646

4747

48+
def test_sample_regular_pass_smote_enn():
49+
smote = SMOTEENN(smote=SMOTE(ratio='auto', random_state=RND_SEED),
50+
enn=EditedNearestNeighbours(ratio='all',
51+
random_state=RND_SEED),
52+
random_state=RND_SEED)
53+
X_resampled, y_resampled = smote.fit_sample(X, Y)
54+
55+
X_gt = np.array([[1.52091956, -0.49283504],
56+
[0.84976473, -0.15570176],
57+
[0.61319159, -0.11571667],
58+
[0.66052536, -0.28246518],
59+
[-0.28162401, -2.10400981],
60+
[0.83680821, 1.72827342],
61+
[0.08711622, 0.93259929]])
62+
y_gt = np.array([0, 0, 0, 0, 1, 1, 1])
63+
assert_allclose(X_resampled, X_gt, rtol=R_TOL)
64+
assert_array_equal(y_resampled, y_gt)
65+
66+
4867
def test_sample_regular_half():
49-
ratio = 0.8
68+
ratio = {0: 10, 1: 12}
5069
smote = SMOTEENN(ratio=ratio, random_state=RND_SEED)
5170
X_resampled, y_resampled = smote.fit_sample(X, Y)
5271

@@ -91,25 +110,6 @@ def test_validate_estimator_default():
91110
assert_array_equal(y_resampled, y_gt)
92111

93112

94-
def test_validate_estimator_deprecation():
95-
smt = SMOTEENN(random_state=RND_SEED)
96-
X_resampled, y_resampled = smt.fit_sample(X, Y)
97-
X_gt = np.array([[1.52091956, -0.49283504],
98-
[0.84976473, -0.15570176],
99-
[0.61319159, -0.11571667],
100-
[0.66052536, -0.28246518],
101-
[-0.28162401, -2.10400981],
102-
[0.83680821, 1.72827342],
103-
[0.08711622, 0.93259929]])
104-
y_gt = np.array([0, 0, 0, 0, 1, 1, 1])
105-
assert_allclose(X_resampled, X_gt, rtol=R_TOL)
106-
assert_array_equal(y_resampled, y_gt)
107-
smt = SMOTEENN(random_state=RND_SEED, k=5)
108-
X_resampled, y_resampled = smt.fit_sample(X, Y)
109-
assert_allclose(X_resampled, X_gt, rtol=R_TOL)
110-
assert_array_equal(y_resampled, y_gt)
111-
112-
113113
def test_error_wrong_object():
114114
smote = 'rnd'
115115
enn = 'rnd'

0 commit comments

Comments
 (0)