Skip to content

Commit 7506185

Browse files
author
Guillaume Lemaitre
committed
Address issue #93
1 parent 11f3865 commit 7506185

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

imblearn/under_sampling/one_sided_selection.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ def sample(self, X, y):
205205
S_x = X[y == key]
206206
S_y = y[y == key]
207207

208+
# Remove the seed from S since that it will be added anyway
209+
S_x = np.delete(S_x, idx_maj_sample, axis=0)
210+
S_y = np.delete(S_y, idx_maj_sample, axis=0)
211+
208212
# Create a k-NN classifier
209213
knn = KNeighborsClassifier(n_neighbors=self.size_ngh,
210214
n_jobs=self.n_jobs,
@@ -221,12 +225,23 @@ def sample(self, X, y):
221225
sel_y = S_y[np.nonzero(pred_S_y != S_y)]
222226

223227
# If we need to offer support for the indices selected
228+
# We concatenate the misclassified samples with the seed and the
229+
# minority samples
224230
if self.return_indices:
225231
idx_tmp = np.nonzero(y == key)[0][np.nonzero(pred_S_y != S_y)]
226-
idx_under = np.concatenate((idx_under, idx_tmp), axis=0)
227-
228-
X_resampled = np.concatenate((X_resampled, sel_x), axis=0)
229-
y_resampled = np.concatenate((y_resampled, sel_y), axis=0)
232+
idx_under = np.concatenate((idx_under,
233+
idx_maj_sample,
234+
idx_tmp),
235+
axis=0)
236+
237+
X_resampled = np.concatenate((X_resampled,
238+
maj_sample,
239+
sel_x),
240+
axis=0)
241+
y_resampled = np.concatenate((y_resampled,
242+
[key] * self.n_seeds_S,
243+
sel_y),
244+
axis=0)
230245

231246
# Find the nearest neighbour of every point
232247
nn = NearestNeighbors(n_neighbors=2, n_jobs=self.n_jobs)
8 Bytes
Binary file not shown.
160 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)