From 0fad976995193e73f0cd4e000863cb4e5b3777ad Mon Sep 17 00:00:00 2001 From: Mark Peng Date: Fri, 14 Dec 2018 17:32:24 +0800 Subject: [PATCH] Fixed TypeError: iteration over a 0-d array issue when no features are rejected. --- boruta/boruta_py.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/boruta/boruta_py.py b/boruta/boruta_py.py index 6122825..99e80d1 100644 --- a/boruta/boruta_py.py +++ b/boruta/boruta_py.py @@ -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: