10000 Merge pull request #6569 from MechCoder/minor · scikit-learn/scikit-learn@56d625f · GitHub
[go: up one dir, main page]

Skip to content

Commit 56d625f

Browse files
committed
Merge pull request #6569 from MechCoder/minor
[MRG+1] MAINT: Simplify n_features_to_select logic in RFECV
2 parents 65b570b + 528533d commit 56d625f

File tree

1 file changed

+6
-9
lines changed
  • sklearn/feature_selection

1 file changed

+6
-9
lines changed

sklearn/feature_selection/rfe.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,11 @@ def fit(self, X, y):
421421
func(rfe, self.estimator, X, y, train, test, scorer)
422422
for train, test in cv.split(X, y))
423423

424-
scores = np.sum(scores, axis=0)[::-1]
425-
# The index in 'scores' when 'n_features' features are selected
426-
n_feature_index = np.ceil((n_features - n_features_to_select) /
427-
float(self.step))
428-
n_features_to_select = max(n_features_to_select,
429-
n_features - ((n_feature_index -
430-
np.argmax(scores)) *
431-
self.step))
424+
scores = np.sum(scores, axis=0)
425+
n_features_to_select = max(
426+
n_features - (np.argmax(scores) * self.step),
427+
n_features_to_select)
428+
432429
# Re-execute an elimination with best_k over the whole set
433430
rfe = RFE(estimator=self.estimator,
434431
n_features_to_select=n_features_to_select, step=self.step)
@@ -444,5 +441,5 @@ def fit(self, X, y):
444441

445442
# Fixing a normalization error, n is equal to get_n_splits(X, y) - 1
446443
# here, the scores are normalized by get_n_splits(X, y)
447-
self.grid_scores_ = scores / cv.get_n_splits(X, y)
444+
self.grid_scores_ = scores[::-1] / cv.get_n_splits(X, y)
448445
return self

0 commit comments

Comments
 (0)
0