.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/feature_selection/plot_rfe_digits.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_auto_examples_feature_selection_plot_rfe_digits.py>` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_feature_selection_plot_rfe_digits.py: ============================= é€’å½’ç‰¹å¾æ¶ˆé™¤ ============================= æœ¬ç¤ºä¾‹æ¼”ç¤ºäº†å¦‚ä½•ä½¿ç”¨é€’å½’ç‰¹å¾æ¶ˆé™¤ï¼ˆ:class:`~sklearn.feature_selection.RFE` )æ¥ç¡®å®šå•个åƒç´ 在手写数å—分类ä¸çš„é‡è¦æ€§ã€‚:class:`~sklearn.feature_selection.RFE` 递归地移除最ä¸é‡è¦çš„特å¾ï¼Œæ ¹æ®å…¶é‡è¦æ€§åˆ†é…排å,其ä¸è¾ƒé«˜çš„ `ranking_` 值表示较低的é‡è¦æ€§ã€‚排å通过è“色阴影和åƒç´ 注释进行å¯è§†åŒ–,以æé«˜æ¸…晰度。æ£å¦‚é¢„æœŸçš„é‚£æ ·ï¼Œä½äºŽå›¾åƒä¸å¿ƒçš„åƒç´ 比边缘的åƒç´ 更具预测性。 .. note:: å¦è¯·å‚è§ :ref:`sphx_glr_auto_examples_feature_selection_plot_rfe_with_cross_validation.py` .. GENERATED FROM PYTHON SOURCE LINES 13-48 .. image-sg:: /auto_examples/feature_selection/images/sphx_glr_plot_rfe_digits_001.png :alt: Ranking of pixels with RFE (Logistic Regression) :srcset: /auto_examples/feature_selection/images/sphx_glr_plot_rfe_digits_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt from sklearn.datasets import load_digits from sklearn.feature_selection import RFE from sklearn.linear_model import LogisticRegression from sklearn.pipeline import Pipeline from sklearn.preprocessing import MinMaxScaler # åŠ è½½æ•°å—æ•°æ®é›† digits = load_digits() X = digits.images.reshape((len(digits.images), -1)) y = digits.target pipe = Pipeline( [ ("scaler", MinMaxScaler()), ("rfe", RFE(estimator=LogisticRegression(), n_features_to_select=1, step=1)), ] ) pipe.fit(X, y) ranking = pipe.named_steps["rfe"].ranking_.reshape(digits.images[0].shape) # 绘制åƒç´ 排å plt.matshow(ranking, cmap=plt.cm.Blues) # æ·»åŠ åƒç´ ç¼–å·çš„æ³¨é‡Š for i in range(ranking.shape[0]): for j in range(ranking.shape[1]): plt.text(j, i, str(ranking[i, j]), ha="center", va="center", color="black") plt.colorbar() plt.title("Ranking of pixels with RFE\n(Logistic Regression)") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.426 seconds) .. _sphx_glr_download_auto_examples_feature_selection_plot_rfe_digits.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-learn/scikit-learn/main?urlpath=lab/tree/notebooks/auto_examples/feature_selection/plot_rfe_digits.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_rfe_digits.ipynb <plot_rfe_digits.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_rfe_digits.py <plot_rfe_digits.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_rfe_digits.zip <plot_rfe_digits.zip>` .. include:: plot_rfe_digits.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_