.. 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 Click :ref:`here ` 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. .. note:: See also :ref:`sphx_glr_auto_examples_feature_selection_plot_rfe_with_cross_validation.py` .. GENERATED FROM PYTHON SOURCE LINES 15-38 .. 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:: default # 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 5.883 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-python :download:`Download Python source code: demo_featureSelection.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_featureSelection.ipynb `