Skip to content

Commit e82fe2c

Browse files
committed
pep8
1 parent dbb0564 commit e82fe2c

File tree

3 files changed

+160
-158
lines changed

3 files changed

+160
-158
lines changed

imblearn/combine/_preprocess/_spider.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
SEL_KIND = ('weak', 'relabel', 'strong')
2020

2121

22-
@Substitution(sampling_strategy=BasePreprocessSampler._sampling_strategy_docstring)
22+
@Substitution(
23+
sampling_strategy=BasePreprocessSampler._sampling_strategy_docstring)
2324
class SPIDER(BasePreprocessSampler):
2425
"""Perform filtering and over-sampling using Selective Pre-processing of
2526
Imbalanced Data (SPIDER) sampling approach for imbalanced datasets.
@@ -81,7 +82,7 @@ class SPIDER(BasePreprocessSampler):
8182
8283
Examples
8384
--------
84-
85+
8586
>>> from collections import Counter
8687
>>> from sklearn.datasets import make_classification
8788
>>> from imblearn.combine import \
@@ -166,7 +167,7 @@ def _knn_correct(self, X, y, additional=False):
166167
The label samples to classify.
167168
168169
additional : bool, optional (default=False)
169-
Flag to indicate whether to increase ``n_neighbors`` by
170+
Flag to indicate whether to increase ``n_neighbors`` by
170171
additional_neighbors``.
171172
172173
Returns
@@ -230,7 +231,7 @@ def _amplify(self, X, y, additional=False):
230231
else:
231232
X_new = np.repeat(X, amplify_amounts, axis=0)
232233
y_new = np.repeat(y, amplify_amounts)
233-
234+
234235
self._X_resampled.append(X_new)
235236
self._y_resampled.append(y_new)
236237
return nn_indices

imblearn/combine/tests/test_spider.py

Lines changed: 153 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,39 @@
1616
[-11.72, -2.34],
1717
[-11.43, -5.85],
1818
[-10.66, -4.33],
19-
[ -9.64, -7.05],
20-
[ -8.39, -4.41],
21-
[ -8.07, -5.66],
22-
[ -7.28, 0.91],
23-
[ -7.24, -2.41],
24-
[ -6.13, -4.81],
25-
[ -5.92, -6.81],
26-
[ -4. , -1.81],
27-
[ -3.96, 2.67],
28-
[ -3.74, -7.31],
29-
[ -2.96, 4.69],
30-
[ -1.56, -2.33],
31-
[ -1.02, -4.57],
32-
[ 0.46, 4.07],
33-
[ 1.2 , -1.53],
34-
[ 1.32, 0.41],
35-
[ 1.56, -5.19],
36-
[ 2.52, 5.89],
37-
[ 3.03, -4.15],
38-
[ 4. , -0.59],
39-
[ 4.4 , 2.07],
40-
[ 4.41, -7.45],
41-
[ 4.45, -4.12],
42-
[ 5.13, -6.28],
43-
[ 5.4 , -5 ],
44-
[ 6.26, 4.65],
45-
[ 7.02, -6.22],
46-
[ 7.5 , -0.11],
47-
[ 8.1 , -2.05],
48-
[ 8.42, 2.47],
49-
[ 9.62, 3.87],
50-
[ 10.54, -4.47],
51-
[ 11.42, 0.01]
19+
[-9.64, -7.05],
20+
[-8.39, -4.41],
21+
[-8.07, -5.66],
22+
[-7.28, 0.91],
23+
[-7.24, -2.41],
24+
[-6.13, -4.81],
25+
[-5.92, -6.81],
26+
[-4., -1.81],
27+
[-3.96, 2.67],
28+
[-3.74, -7.31],
29+
[-2.96, 4.69],
30+
[-1.56, -2.33],
31+
[-1.02, -4.57],
32+
[0.46, 4.07],
33+
[1.2, -1.53],
34+
[1.32, 0.41],
35+
[1.56, -5.19],
36+
[2.52, 5.89],
37+
[3.03, -4.15],
38+
[4., -0.59],
39+
[4.4, 2.07],
40+
[4.41, -7.45],
41+
[4.45, -4.12],
42+
[5.13, -6.28],
43+
[5.4, -5],
44+
[6.26, 4.65],
45+
[7.02, -6.22],
46+
[7.5, -0.11],
47+
[8.1, -2.05],
48+
[8.42, 2.47],
49+
[9.62, 3.87],
50+
[10.54, -4.47],
51+
[11.42, 0.01]
5252
])
5353
y = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0,
5454
0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0])
@@ -92,43 +92,43 @@ def test_dense_sparse(fmt):
9292

9393
def test_weak():
9494
X_expected = np.array([
95-
[ -3.96, 2.67],
96-
[ -3.96, 2.67],
97-
[ -3.96, 2.67],
98-
[ 3.03, -4.15],
99-
[-11.83, -6.81],
100-
[-11.72, -2.34],
101-
[-11.43, -5.85],
102-
[-10.66, -4.33],
103-
[ -9.64, -7.05],
104-
[ -8.39, -4.41],
105-
[ -8.07, -5.66],
106-
[ -7.28, 0.91],
107-
[ -7.24, -2.41],
108-
[ -6.13, -4.81],
109-
[ -5.92, -6.81],
110-
[ -4. , -1.81],
111-
[ -3.96, 2.67],
112-
[ -3.74, -7.31],
113-
[ -2.96, 4.69],
114-
[ -1.56, -2.33],
115-
[ -1.02, -4.57],
116-
[ 0.46, 4.07],
117-
[ 1.2 , -1.53],
118-
[ 1.32, 0.41],
119-
[ 1.56, -5.19],
120-
[ 3.03, -4.15],
121-
[ 4. , -0.59],
122-
[ 4.4 , 2.07],
123-
[ 4.41, -7.45],
124-
[ 5.13, -6.28],
125-
[ 5.4 , -5. ],
126-
[ 6.26, 4.65],
127-
[ 7.02, -6.22],
128-
[ 8.1 , -2.05],
129-
[ 8.42, 2.47],
130-
[ 10.54, -4.47],
131-
[ 11.42, 0.01]
95+
[-3.96, 2.67],
96+
[-3.96, 2.67],
97+
[-3.96, 2.67],
98+
[3.03, -4.15],
99+
[-11.83, -6.81],
100+
[-11.72, -2.34],
101+
[-11.43, -5.85],
102+
[-10.66, -4.33],
103+
[-9.64, -7.05],
104+
[-8.39, -4.41],
105+
[-8.07, -5.66],
106+
[-7.28, 0.91],
107+
[-7.24, -2.41],
108+
[-6.13, -4.81],
109+
[-5.92, -6.81],
110+
[-4., -1.81],
111+
[-3.96, 2.67],
112+
[-3.74, -7.31],
113+
[-2.96, 4.69],
114+
[-1.56, -2.33],
115+
[-1.02, -4.57],
116+
[0.46, 4.07],
117+
[1.2, -1.53],
118+
[1.32, 0.41],
119+
[1.56, -5.19],
120+
[3.03, -4.15],
121+
[4., -0.59],
122+
[4.4, 2.07],
123+
[4.41, -7.45],
124+
[5.13, -6.28],
125+
[5.4, -5.],
126+
[6.26, 4.65],
127+
[7.02, -6.22],
128+
[8.1, -2.05],
129+
[8.42, 2.47],
130+
[10.54, -4.47],
131+
[11.42, 0.01]
132132
])
133133
y_expected = np.array([1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
134134
0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0])
@@ -142,46 +142,46 @@ def test_weak():
142142

143143
def test_relabel():
144144
X_expected = np.array([
145-
[ -3.96, 2.67],
146-
[ -3.96, 2.67],
147-
[ -3.96, 2.67],
148-
[ 3.03, -4.15],
149-
[-11.83, -6.81],
150-
[-11.72, -2.34],
151-
[-11.43, -5.85],
152-
[-10.66, -4.33],
153-
[ -9.64, -7.05],
154-
[ -8.39, -4.41],
155-
[ -8.07, -5.66],
156-
[ -7.28, 0.91],
157-
[ -7.24, -2.41],
158-
[ -6.13, -4.81],
159-
[ -5.92, -6.81],
160-
[ -4. , -1.81],
161-
[ -3.96, 2.67],
162-
[ -3.74, -7.31],
163-
[ -2.96, 4.69],
164-
[ -1.56, -2.33],
165-
[ -1.02, -4.57],
166-
[ 0.46, 4.07],
167-
[ 1.2 , -1.53],
168-
[ 1.32, 0.41],
169-
[ 1.56, -5.19],
170-
[ 3.03, -4.15],
171-
[ 4. , -0.59],
172-
[ 4.4 , 2.07],
173-
[ 4.41, -7.45],
174-
[ 4.45, -4.12],
175-
[ 5.13, -6.28],
176-
[ 5.4 , -5. ],
177-
[ 6.26, 4.65],
178-
[ 7.02, -6.22],
179-
[ 7.5 , -0.11],
180-
[ 8.1 , -2.05],
181-
[ 8.42, 2.47],
182-
[ 9.62, 3.87],
183-
[ 10.54, -4.47],
184-
[ 11.42, 0.01]
145+
[-3.96, 2.67],
146+
[-3.96, 2.67],
147+
[-3.96, 2.67],
148+
[3.03, -4.15],
149+
[-11.83, -6.81],
150+
[-11.72, -2.34],
151+
[-11.43, -5.85],
152+
[-10.66, -4.33],
153+
[-9.64, -7.05],
154+
[-8.39, -4.41],
155+
[-8.07, -5.66],
156+
[-7.28, 0.91],
157+
[-7.24, -2.41],
158+
[-6.13, -4.81],
159+
[-5.92, -6.81],
160+
[-4., -1.81],
161+
[-3.96, 2.67],
162+
[-3.74, -7.31],
163+
[-2.96, 4.69],
164+
[-1.56, -2.33],
165+
[-1.02, -4.57],
166+
[0.46, 4.07],
167+
[1.2, -1.53],
168+
[1.32, 0.41],
169+
[1.56, -5.19],
170+
[3.03, -4.15],
171+
[4., -0.59],
172+
[4.4, 2.07],
173+
[4.41, -7.45],
174+
[4.45, -4.12],
175+
[5.13, -6.28],
176+
[5.4, -5.],
177+
[6.26, 4.65],
178+
[7.02, -6.22],
179+
[7.5, -0.11],
180+
[8.1, -2.05],
181+
[8.42, 2.47],
182+
[9.62, 3.87],
183+
[10.54, -4.47],
184+
[11.42, 0.01]
185185
])
186186
y_expected = np.array([1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
187187
0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0])
@@ -195,50 +195,51 @@ def test_relabel():
195195

196196
def test_strong():
197197
X_expected = np.array([
198-
[ 1.2 , -1.53],
199-
[ 3.03, -4.15],
200-
[ -3.96, 2.67],
201-
[ -3.96, 2.67],
202-
[ -3.96, 2.67],
203-
[ -3.96, 2.67],
204-
[ -3.96, 2.67],
205-
[ 8.42, 2.47],
206-
[-11.83, -6.81],
207-
[-11.72, -2.34],
208-
[-11.43, -5.85],
209-
[-10.66, -4.33],
210-
[ -9.64, -7.05],
211-
[ -8.39, -4.41],
212-
[ -8.07, -5.66],
213-
[ -7.28, 0.91],
214-
[ -7.24, -2.41],
215-
[ -6.13, -4.81],
216-
[ -5.92, -6.81],
217-
[ -4. , -1.81],
218-
[ -3.96, 2.67],
219-
[ -3.74, -7.31],
220-
[ -2.96, 4.69],
221-
[ -1.56, -2.33],
222-
[ -1.02, -4.57],
223-
[ 0.46, 4.07],
224-
[ 1.2 , -1.53],
225-
[ 1.32, 0.41],
226-
[ 1.56, -5.19],
227-
[ 3.03, -4.15],
228-
[ 4. , -0.59],
229-
[ 4.4 , 2.07],
230-
[ 4.41, -7.45],
231-
[ 5.13, -6.28],
232-
[ 5.4 , -5. ],
233-
[ 6.26, 4.65],
234-
[ 7.02, -6.22],
235-
[ 8.1 , -2.05],
236-
[ 8.42, 2.47],
237-
[ 10.54, -4.47],
238-
[ 11.42, 0.01]
198+
[1.2, -1.53],
199+
[3.03, -4.15],
200+
[-3.96, 2.67],
201+
[-3.96, 2.67],
202+
[-3.96, 2.67],
203+
[-3.96, 2.67],
204+
[-3.96, 2.67],
205+
[8.42, 2.47],
206+
[-11.83, -6.81],
207+
[-11.72, -2.34],
208+
[-11.43, -5.85],
209+
[-10.66, -4.33],
210+
[-9.64, -7.05],
211+
[-8.39, -4.41],
212+
[-8.07, -5.66],
213+
[-7.28, 0.91],
214+
[-7.24, -2.41],
215+
[-6.13, -4.81],
216+
[-5.92, -6.81],
217+
[-4., -1.81],
218+
[-3.96, 2.67],
219+
[-3.74, -7.31],
220+
[-2.96, 4.69],
221+
[-1.56, -2.33],
222+
[-1.02, -4.57],
223+
[0.46, 4.07],
224+
[1.2, -1.53],
225+
[1.32, 0.41],
226+
[1.56, -5.19],
227+
[3.03, -4.15],
228+
[4., -0.59],
229+
[4.4, 2.07],
230+
[4.41, -7.45],
231+
[5.13, -6.28],
232+
[5.4, -5.],
233+
[6.26, 4.65],
234+
[7.02, -6.22],
235+
[8.1, -2.05],
236+
[8.42, 2.47],
237+
[10.54, -4.47],
238+
[11.42, 0.01]
239239
])
240240
y_expected = np.array([1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
241-
0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0])
241+
0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0,
242+
0])
242243

243244
strong = SPIDER(kind='strong')
244245
X_resampled, y_resampled = strong.fit_resample(X, y)

imblearn/utils/_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ def check_sampling_strategy(sampling_strategy, y, sampling_type, **kwargs):
369369
370370
- When ``str``, specify the class targeted by the resampling. For
371371
**under- and over-sampling methods**, the number of samples in the
372-
different classes will be equalized. For **cleaning and
373-
preprocessing methods**, the number of samples will not be equal.
372+
different classes will be equalized. For **cleaning and
373+
preprocessing methods**, the number of samples will not be equal.
374374
Possible choices are:
375375
376376
``'minority'``: resample only the minority class;

0 commit comments

Comments
 (0)