Skip to content

Commit 437bc53

Browse files
author
Guillaume Lemaitre
committed
Remove nonzero occurence in BC
1 parent a955c24 commit 437bc53

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

imblearn/ensemble/balance_cascade.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _sample(self, X, y):
168168
# Keep the indices of the minority class somewhere if we need to
169169
# return them later
170170
if self.return_indices:
171-
idx_min = np.nonzero(y == self.min_c_)[0]
171+
idx_min = np.flatnonzero(y == self.min_c_)
172172

173173
# Condition to initiliase before the search
174174
b_subset_search = True
@@ -190,7 +190,7 @@ def _sample(self, X, y):
190190
# Generate an appropriate number of index to extract
191191
# from the majority class depending of the false classification
192192
# rate of the previous iteration
193-
idx_sel_from_maj = random_state.choice(np.nonzero(b_sel_N)[0],
193+
idx_sel_from_maj = random_state.choice(np.flatnonzero(b_sel_N),
194194
size=num_samples,
195195
replace=False)
196196
idx_sel_from_maj = np.concatenate((idx_mis_class,
@@ -236,8 +236,8 @@ def _sample(self, X, y):
236236
# next round
237237

238238
# Find the misclassified index to keep them for the next round
239-
idx_mis_class = idx_sel_from_maj[np.nonzero(pred_label !=
240-
N_y[idx_sel_from_maj])]
239+
idx_mis_class = idx_sel_from_maj[np.flatnonzero(
240+
pred_label != N_y[idx_sel_from_maj])]
241241
self.logger.debug('Elements misclassified: %s', idx_mis_class)
242242

243243
# Count how many random element will be selected
@@ -257,7 +257,7 @@ def _sample(self, X, y):
257257
if n_subsets == (self.n_max_subset - 1):
258258
b_subset_search = False
259259
# Select the remaining data
260-
idx_sel_from_maj = np.nonzero(b_sel_N)[0]
260+
idx_sel_from_maj = np.flatnonzero(b_sel_N)
261261
idx_sel_from_maj = np.concatenate((idx_mis_class,
262262
idx_sel_from_maj),
263263
axis=0).astype(int)
@@ -287,7 +287,7 @@ def _sample(self, X, y):
287287
if num_samples > np.count_nonzero(b_sel_N):
288288
b_subset_search = False
289289
# Select the remaining data
290-
idx_sel_from_maj = np.nonzero(b_sel_N)[0]
290+
idx_sel_from_maj = np.flatnonzero(b_sel_N)
291291
idx_sel_from_maj = np.concatenate((idx_mis_class,
292292
idx_sel_from_maj),
293293
axis=0).astype(int)

0 commit comments

Comments
 (0)