.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "glr_examples/base/plot_sbs_feature_selector.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_base_plot_sbs_feature_selector.py: ============================================ Plot Sequential Backward Selection (SBS) ============================================ shows the SBS in action with the classification accuracy of the KNeighbors Classifier that was calculated on the validation dataset. .. GENERATED FROM PYTHON SOURCE LINES 10-13 .. code-block:: Python # Author: L.Kouadio # Licence: BSD-3 .. GENERATED FROM PYTHON SOURCE LINES 14-15 imort the required modules and preprocess the data .. GENERATED FROM PYTHON SOURCE LINES 15-43 .. code-block:: Python from watex.datasets import fetch_data from watex.exlib.sklearn import SimpleImputer from watex.utils import selectfeatures import matplotlib.pyplot as plt from watex.exlib.sklearn import KNeighborsClassifier from watex.base import SequentialBackwardSelection data= fetch_data("bagoue original").get('data=dfy1') # encoded flow categories y = data.flow ; X= data.drop(columns='flow') # select the numerical features X =selectfeatures(X, include ='number') # imputed the missing data X = SimpleImputer().fit_transform(X) knn = KNeighborsClassifier(n_neighbors=5) sbs= SequentialBackwardSelection(knn, k_features=1) sbs.fit(X, y) k_feat = [len(k) for k in sbs.subsets_] plt.plot (k_feat, sbs.scores_, marker ='o') #plt.ylim ([]) plt.ylabel ('Accuracy') plt.xlabel ("Number of features") plt.grid () plt.tight_layout() plt.show() # AS we can see the classifier achieve more than 70% accuracy for # k =3, 4, 5. Thus, we can reduce the number of features down to. .. image-sg:: /glr_examples/base/images/sphx_glr_plot_sbs_feature_selector_001.png :alt: plot sbs feature selector :srcset: /glr_examples/base/images/sphx_glr_plot_sbs_feature_selector_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.339 seconds) .. _sphx_glr_download_glr_examples_base_plot_sbs_feature_selector.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/base/plot_sbs_feature_selector.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sbs_feature_selector.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sbs_feature_selector.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_