.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "glr_examples/utils/plot_model_confusion_matrix.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_model_confusion_matrix.py: ================================================= Plot confusion matrix ================================================= plots a confusion matrix for a single classifier model. .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python # Author: L.Kouadio # Licence: BSD-3-clause .. GENERATED FROM PYTHON SOURCE LINES 12-14 Import the required models and fetch a an Ababoost model for instance then plot the confusion metric .. GENERATED FROM PYTHON SOURCE LINES 14-26 .. code-block:: Python import matplotlib.pyplot as plt plt.style.use ('classic') from watex.datasets import fetch_data from watex.exlib.sklearn import train_test_split from watex.models import pModels from watex.utils.plotutils import plot_confusion_matrix # split the data . Note that fetch_data output X and y X, Xt, y, yt = train_test_split (* fetch_data ('bagoue analysed'), test_size =.25 ) # train the model with the best estimator pmo = pModels (model ='ada' ) pmo.fit(X, y ) print(pmo.estimator_ ) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/watex/envs/0.3.2/lib/python3.10/site-packages/sklearn/ensemble/_weight_boosting.py:519: FutureWarning: The SAMME.R algorithm (the default) is deprecated and will be removed in 1.6. Use the SAMME algorithm to circumvent this warning. AdaBoostClassifier(estimator=DecisionTreeClassifier(criterion='entropy', max_depth=7), learning_rate=0.06) .. GENERATED FROM PYTHON SOURCE LINES 27-29 Predict the score using under the hood the best estimator for adaboost classifier .. GENERATED FROM PYTHON SOURCE LINES 29-34 .. code-block:: Python ypred = pmo.predict(Xt) # now plot the score plot_confusion_matrix (yt , ypred ) .. image-sg:: /glr_examples/utils/images/sphx_glr_plot_model_confusion_matrix_001.png :alt: plot model confusion matrix :srcset: /glr_examples/utils/images/sphx_glr_plot_model_confusion_matrix_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none array([[25, 4, 0, 1], [ 9, 16, 3, 2], [ 1, 0, 7, 4], [ 0, 1, 2, 11]]) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.323 seconds) .. _sphx_glr_download_glr_examples_utils_plot_model_confusion_matrix.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_model_confusion_matrix.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_model_confusion_matrix.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_model_confusion_matrix.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_