.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "glr_examples/utils/plot_sbs_feature_selection.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 or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_glr_examples_utils_plot_sbs_feature_selection.py: ================================================= Plot feature selection with SBS ================================================= selects features using the sequential Backward Selection (SBS) algorithm. .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python # Author: L.Kouadio # Licence: BSD-3-clause .. GENERATED FROM PYTHON SOURCE LINES 12-13 * SBS in action with fitted data .. GENERATED FROM PYTHON SOURCE LINES 13-28 .. code-block:: Python import matplotlib.pyplot as plt from watex.exlib.sklearn import KNeighborsClassifier , train_test_split from watex.datasets import fetch_data from watex.base import SequentialBackwardSelection from watex.utils.plotutils import plot_sbs_feature_selection plt.style.use ('classic') X, y = fetch_data('bagoue analysed') # data already standardized Xtrain, Xt, ytrain, yt = train_test_split(X, y) knn = KNeighborsClassifier(n_neighbors=5) sbs= SequentialBackwardSelection (knn) sbs.fit(Xtrain, ytrain ) plot_sbs_feature_selection(sbs) .. image-sg:: /glr_examples/utils/images/sphx_glr_plot_sbs_feature_selection_001.png :alt: plot sbs feature selection :srcset: /glr_examples/utils/images/sphx_glr_plot_sbs_feature_selection_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 29-30 * Plot estimator with no prefit SBS .. GENERATED FROM PYTHON SOURCE LINES 30-34 .. code-block:: Python plot_sbs_feature_selection(knn, Xtrain, ytrain) # yield the same result # The above pplot indicates that performance is mostly achieved from # feature 3 to 4 before droppint around 60% with feature equals to 8 .. image-sg:: /glr_examples/utils/images/sphx_glr_plot_sbs_feature_selection_002.png :alt: plot sbs feature selection :srcset: /glr_examples/utils/images/sphx_glr_plot_sbs_feature_selection_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.559 seconds) .. _sphx_glr_download_glr_examples_utils_plot_sbs_feature_selection.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/watex/watex/0.3.X?urlpath=lab/tree/notebooks/glr_examples/utils/plot_sbs_feature_selection.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sbs_feature_selection.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sbs_feature_selection.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_