Recursive feature eliminationΒΆ

A recursive feature elimination example showing the relevance of pixels in a digit classification task.


from sklearn.svm import SVC
from sklearn.datasets import load_digits
from sklearn.feature_selection import RFE
import matplotlib.pyplot as plt

# Load the digits dataset
digits = load_digits()
X = digits.images.reshape((len(digits.images), -1))
y =

# Create the RFE object and rank each pixel
svc = SVC(kernel="linear", C=1)
rfe = RFE(estimator=svc, n_features_to_select=1, step=1), y)
ranking = rfe.ranking_.reshape(digits.images[0].shape)

# Plot pixel ranking
plt.title("Ranking of pixels with RFE")

Total running time of the script: ( 0 minutes 4.118 seconds)

Gallery generated by Sphinx-Gallery