@@ -331,20 +331,24 @@ def _fit(self, X, y):
331
331
not_selected = np .setdiff1d (np .arange (n_feat ), selected )
332
332
# large importance values should rank higher = lower ranks -> *(-1)
333
333
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 )
338
334
339
335
# 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 )
348
352
349
353
# notify user
350
354
if self .verbose > 0 :
0 commit comments