Skip to content

Commit

Permalink
DOC Added explicit min_features variable to RFECV example (#18091)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
  • Loading branch information
eschibli and thomasjpfan committed Aug 20, 2020
1 parent 87eea7d commit bf121f4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions examples/feature_selection/plot_rfe_with_cross_validation.py
Expand Up @@ -23,8 +23,11 @@
svc = SVC(kernel="linear")
# The "accuracy" scoring is proportional to the number of correct
# classifications

min_features_to_select = 1 # Minimum number of features to consider
rfecv = RFECV(estimator=svc, step=1, cv=StratifiedKFold(2),
scoring='accuracy')
scoring='accuracy',
min_features_to_select=min_features_to_select)
rfecv.fit(X, y)

print("Optimal number of features : %d" % rfecv.n_features_)
Expand All @@ -33,5 +36,7 @@
plt.figure()
plt.xlabel("Number of features selected")
plt.ylabel("Cross validation score (nb of correct classifications)")
plt.plot(range(1, len(rfecv.grid_scores_) + 1), rfecv.grid_scores_)
plt.plot(range(min_features_to_select,
len(rfecv.grid_scores_) + min_features_to_select),
rfecv.grid_scores_)
plt.show()

0 comments on commit bf121f4

Please sign in to comment.