.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\python_packages\scikit-learn\demo_featureSelection.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_11_demos_python_packages_scikit-learn_demo_featureSelection.py: Recursive feature elimination ============================= An example of ``scikit-learn``, copied from `scikit-learn.org `_. A recursive feature elimination example showing the relevance of pixels in a digit classification task. .. GENERATED FROM PYTHON SOURCE LINES 10-33 .. image-sg:: /11_demos/python_packages/scikit-learn/images/sphx_glr_demo_featureSelection_001.png :alt: Ranking of pixels with RFE :srcset: /11_demos/python_packages/scikit-learn/images/sphx_glr_demo_featureSelection_001.png :class: sphx-glr-single-img .. code-block:: Python # noqa: E501 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 = digits.target # 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) rfe.fit(X, y) ranking = rfe.ranking_.reshape(digits.images[0].shape) # Plot pixel ranking plt.matshow(ranking, cmap=plt.cm.Blues) plt.colorbar() plt.title("Ranking of pixels with RFE") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.328 seconds) .. _sphx_glr_download_11_demos_python_packages_scikit-learn_demo_featureSelection.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_featureSelection.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_featureSelection.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_featureSelection.zip `