Skip to content

Commit 0fad976

Browse files
author
Mark Peng
committed
Fixed TypeError: iteration over a 0-d array issue when no features are rejected.
1 parent 3657c00 commit 0fad976

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

boruta/boruta_py.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,24 @@ def _fit(self, X, y):
331331
not_selected = np.setdiff1d(np.arange(n_feat), selected)
332332
# large importance values should rank higher = lower ranks -> *(-1)
333333
imp_history_rejected = imp_history[1:, not_selected] * -1
334-
# calculate ranks in each iteration, then median of ranks across feats
335-
iter_ranks = self._nanrankdata(imp_history_rejected, axis=1)
336-
rank_medians = np.nanmedian(iter_ranks, axis=0)
337-
ranks = self._nanrankdata(rank_medians, axis=0)
338334

339335
# update rank for not_selected features
340-
if not_selected.shape[0] > 0:
341-
# set smallest rank to 3 if there are tentative feats
342-
if tentative.shape[0] > 0:
343-
ranks = ranks - np.min(ranks) + 3
344-
else:
345-
# and 2 otherwise
346-
ranks = ranks - np.min(ranks) + 2
347-
self.ranking_[not_selected] = ranks
336+
if not_selected.shape[0] > 0 and not_selected.shape[1] > 0:
337+
# calculate ranks in each iteration, then median of ranks across feats
338+
iter_ranks = self._nanrankdata(imp_history_rejected, axis=1)
339+
rank_medians = np.nanmedian(iter_ranks, axis=0)
340+
ranks = self._nanrankdata(rank_medians, axis=0)
341+
342+
# set smallest rank to 3 if there are tentative feats
343+
if tentative.shape[0] > 0:
344+
ranks = ranks - np.min(ranks) + 3
345+
else:
346+
# and 2 otherwise
347+
ranks = ranks - np.min(ranks) + 2
348+
self.ranking_[not_selected] = ranks
349+
else:
350+
# all are selected, thus we set feature supports to True
351+
self.support_ = np.ones(n_feat, dtype=np.bool)
348352

349353
# notify user
350354
if self.verbose > 0:

0 commit comments

Comments
 (0)