Skip to content
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

[MRG] Address #131 - Replace nonzero by flatnonzero whenever possible #132

Merged
merged 8 commits into from
Aug 30, 2016
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove nonzero occurence in OSS
  • Loading branch information
Guillaume Lemaitre committed Aug 30, 2016
commit 8baa233ffa35c70a19825c1de4ddbf84387ea91c
9 changes: 5 additions & 4 deletions imblearn/under_sampling/one_sided_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _sample(self, X, y):

# If we need to offer support for the indices
if self.return_indices:
idx_under = np.nonzero(y == self.min_c_)[0]
idx_under = np.flatnonzero(y == self.min_c_)

# Loop over the other classes under picking at random
for key in self.stats_c_.keys():
Expand Down Expand Up @@ -177,14 +177,15 @@ def _sample(self, X, y):
pred_S_y = knn.predict(S_x)

# Find the misclassified S_y
sel_x = np.squeeze(S_x[np.nonzero(pred_S_y != S_y), :])
sel_y = S_y[np.nonzero(pred_S_y != S_y)]
sel_x = S_x[np.flatnonzero(pred_S_y != S_y), :]
sel_y = S_y[np.flatnonzero(pred_S_y != S_y)]

# If we need to offer support for the indices selected
# We concatenate the misclassified samples with the seed and the
# minority samples
if self.return_indices:
idx_tmp = np.nonzero(y == key)[0][np.nonzero(pred_S_y != S_y)]
idx_tmp = np.flatnonzero(y == key)[
np.flatnonzero(pred_S_y != S_y)]
idx_under = np.concatenate((idx_under,
idx_maj_sample,
idx_tmp),
Expand Down