Skip to content

Commit

Permalink
Merge pull request #46 from guitarmind/master
Browse files Browse the repository at this point in the history
Fix TypeError: iteration over a 0-d array error when no features are rejected
  • Loading branch information
danielhomola committed Dec 17, 2018
2 parents 3657c00 + 0fad976 commit 52d504b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions boruta/boruta_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,24 @@ def _fit(self, X, y):
not_selected = np.setdiff1d(np.arange(n_feat), selected)
# large importance values should rank higher = lower ranks -> *(-1)
imp_history_rejected = imp_history[1:, not_selected] * -1
# calculate ranks in each iteration, then median of ranks across feats
iter_ranks = self._nanrankdata(imp_history_rejected, axis=1)
rank_medians = np.nanmedian(iter_ranks, axis=0)
ranks = self._nanrankdata(rank_medians, axis=0)

# update rank for not_selected features
if not_selected.shape[0] > 0:
# set smallest rank to 3 if there are tentative feats
if tentative.shape[0] > 0:
ranks = ranks - np.min(ranks) + 3
else:
# and 2 otherwise
ranks = ranks - np.min(ranks) + 2
self.ranking_[not_selected] = ranks
if not_selected.shape[0] > 0 and not_selected.shape[1] > 0:
# calculate ranks in each iteration, then median of ranks across feats
iter_ranks = self._nanrankdata(imp_history_rejected, axis=1)
rank_medians = np.nanmedian(iter_ranks, axis=0)
ranks = self._nanrankdata(rank_medians, axis=0)

# set smallest rank to 3 if there are tentative feats
if tentative.shape[0] > 0:
ranks = ranks - np.min(ranks) + 3
else:
# and 2 otherwise
ranks = ranks - np.min(ranks) + 2
self.ranking_[not_selected] = ranks
else:
# all are selected, thus we set feature supports to True
self.support_ = np.ones(n_feat, dtype=np.bool)

# notify user
if self.verbose > 0:
Expand Down

0 comments on commit 52d504b

Please sign in to comment.