.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "glr_examples/view/plot_confusion_matrix_metric.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_view_plot_confusion_matrix_metric.py: ================================================= Plot confusion matrix metric ================================================= displays the confusion matrix for errors analysis. .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python # Author: L.Kouadio # Licence: BSD-3-clause .. GENERATED FROM PYTHON SOURCE LINES 12-13 Fetch data and evaluate the model .. GENERATED FROM PYTHON SOURCE LINES 13-43 .. code-block:: Python from watex.datasets import fetch_data from watex.exlib.sklearn import SVC from watex.view.mlplot import EvalPlot X, y = fetch_data ('bagoue', return_X_y=True, as_frame =True) # partition the target into 4 clusters-> just for demo b= EvalPlot(scale =True, label_values = 4 ) b.fit_transform (X, y) # prepare our estimator svc_clf = SVC(C=100, gamma=1e-2, kernel='rbf', random_state =42) matshow_kwargs ={ 'aspect': 'auto', # 'auto'equal 'interpolation': None, 'cmap':'jet' } plot_kws ={'lw':3, 'lc':(.9, 0, .8), 'font_size':15., 'cb_format':None, 'xlabel': 'Predicted classes', 'ylabel': 'Actual classes', 'font_weight':None, 'tp_labelbottom':False, 'tp_labeltop':True, 'tp_bottom': False } b.plotConfusionMatrix(clf=svc_clf, matshow_kws = matshow_kwargs, **plot_kws) svc_clf = SVC(C=100, gamma=1e-2, kernel='rbf', random_state =42) .. image-sg:: /glr_examples/view/images/sphx_glr_plot_confusion_matrix_metric_001.png :alt: plot confusion matrix metric :srcset: /glr_examples/view/images/sphx_glr_plot_confusion_matrix_metric_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/watex/envs/v0.3.3/lib/python3.10/site-packages/sklearn/model_selection/_split.py:737: UserWarning: The least populated class in y has only 2 members, which is less than n_splits=5. .. GENERATED FROM PYTHON SOURCE LINES 44-46 visualize the error of confused items rather than samples replace the integer identifier with litteral string .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: Python b.litteral_classes = ['FR0', 'FR1', 'FR2', 'FR3'] b.plotConfusionMatrix(svc_clf, matshow_kws=matshow_kwargs, kind='error', **plot_kws) #Note the confusion items areas. .. image-sg:: /glr_examples/view/images/sphx_glr_plot_confusion_matrix_metric_002.png :alt: plot confusion matrix metric :srcset: /glr_examples/view/images/sphx_glr_plot_confusion_matrix_metric_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/watex/envs/v0.3.3/lib/python3.10/site-packages/numpy/lib/arraysetops.py:612: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison /home/docs/checkouts/readthedocs.org/user_builds/watex/envs/v0.3.3/lib/python3.10/site-packages/sklearn/model_selection/_split.py:737: UserWarning: The least populated class in y has only 2 members, which is less than n_splits=5. EvalPlot(tname= None, objective= None, scale= True, ... , sns_height= 4.0, sns_aspect= 0.7, verbose= 0) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.737 seconds) .. _sphx_glr_download_glr_examples_view_plot_confusion_matrix_metric.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/view/plot_confusion_matrix_metric.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_confusion_matrix_metric.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_confusion_matrix_metric.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_