.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "glr_examples/utils/plot_confusion_matrices.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_confusion_matrices.py: ================================================= Plot confusion matrices ================================================= plots inline multiple confusion matrices from selected models .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python # Author: L.Kouadio # Licence: BSD-3-clause .. GENERATED FROM PYTHON SOURCE LINES 12-15 Plot Radial basis function from the SVM kernel machines, the logit and the randomforest stored as premodels in `p` objects and plot their confusion matrices .. GENERATED FROM PYTHON SOURCE LINES 15-36 .. code-block:: Python # Import the required models and fetch 4 models # derived from RBF SVM kernel machines # for instance then plot the confusion metric 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.premodels import p from watex.utils.plotutils import plot_confusion_matrices # 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 ) # compose the models # from RBF, and poly models =[ p.SVM.rbf.best_estimator_, p.LogisticRegression.best_estimator_, p.RandomForest.best_estimator_ ] print(models ) # now fit all estimators fitted_models = [model.fit(X, y) for model in models ] .. rst-class:: sphx-glr-script-out .. code-block:: none [SVC(C=2.0, coef0=0, degree=1, gamma=0.125), LogisticRegression(), RandomForestClassifier(criterion='entropy', max_depth=16, n_estimators=350)] .. GENERATED FROM PYTHON SOURCE LINES 37-38 * Plot the confusions metrics with the selected estimators .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python plot_confusion_matrices(fitted_models , Xt, yt) .. image-sg:: /glr_examples/utils/images/sphx_glr_plot_confusion_matrices_001.png :alt: SVC, LogisticRegression, RandomForestClassifier :srcset: /glr_examples/utils/images/sphx_glr_plot_confusion_matrices_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 42-43 * Plot using the yellowbrick packages .. GENERATED FROM PYTHON SOURCE LINES 43-44 .. code-block:: Python plot_confusion_matrices(fitted_models , Xt, yt, pkg ='yb') .. rst-class:: sphx-glr-horizontal * .. image-sg:: /glr_examples/utils/images/sphx_glr_plot_confusion_matrices_002.png :alt: SVC Confusion Matrix, LogisticRegression Confusion Matrix, RandomForestClassifier Confusion Matrix :srcset: /glr_examples/utils/images/sphx_glr_plot_confusion_matrices_002.png :class: sphx-glr-multi-img * .. image-sg:: /glr_examples/utils/images/sphx_glr_plot_confusion_matrices_003.png :alt: plot confusion matrices :srcset: /glr_examples/utils/images/sphx_glr_plot_confusion_matrices_003.png :class: sphx-glr-multi-img * .. image-sg:: /glr_examples/utils/images/sphx_glr_plot_confusion_matrices_004.png :alt: plot confusion matrices :srcset: /glr_examples/utils/images/sphx_glr_plot_confusion_matrices_004.png :class: sphx-glr-multi-img * .. image-sg:: /glr_examples/utils/images/sphx_glr_plot_confusion_matrices_005.png :alt: plot confusion matrices :srcset: /glr_examples/utils/images/sphx_glr_plot_confusion_matrices_005.png :class: sphx-glr-multi-img .. 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/yellowbrick/classifier/base.py:232: YellowbrickWarning: could not determine class_counts_ from previously fitted classifier /home/docs/checkouts/readthedocs.org/user_builds/watex/envs/0.3.2/lib/python3.10/site-packages/yellowbrick/classifier/base.py:232: YellowbrickWarning: could not determine class_counts_ from previously fitted classifier /home/docs/checkouts/readthedocs.org/user_builds/watex/envs/0.3.2/lib/python3.10/site-packages/yellowbrick/classifier/base.py:232: YellowbrickWarning: could not determine class_counts_ from previously fitted classifier .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.711 seconds) .. _sphx_glr_download_glr_examples_utils_plot_confusion_matrices.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_confusion_matrices.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_confusion_matrices.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_confusion_matrices.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_