.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "glr_examples/utils/plot_confusion_matrix_sweet.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_matrix_sweet.py: ================================================= Plot confusion matrix sweet ================================================= plots a confusion matrix using the 'yellowbrick' package. .. 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 an extreme gradient boosting 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_yb_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 ='xgboost' ) pmo.fit(X, y ) print(pmo.estimator_ ) # pmo.XGB.best_estimator_ .. rst-class:: sphx-glr-script-out .. code-block:: none XGBClassifier(base_score=None, booster='gbtree', callbacks=None, colsample_bylevel=None, colsample_bynode=None, colsample_bytree=None, device=None, early_stopping_rounds=None, enable_categorical=False, eval_metric=None, feature_types=None, gamma=1.5, grow_policy=None, importance_type=None, interaction_constraints=None, learning_rate=0.07, max_bin=None, max_cat_threshold=None, max_cat_to_onehot=None, max_delta_step=None, max_depth=2, max_leaves=None, min_child_weight=None, missing=nan, monotone_constraints=None, multi_strategy=None, n_estimators=300, n_jobs=None, num_parallel_tree=None, objective='multi:softprob', ...) .. 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-33 .. code-block:: Python ypred = pmo.predict(Xt) # now plot the score plot_yb_confusion_matrix (pmo.XGB.best_estimator_, Xt, yt ) .. image-sg:: /glr_examples/utils/images/sphx_glr_plot_confusion_matrix_sweet_001.png :alt: XGBClassifier Confusion Matrix :srcset: /glr_examples/utils/images/sphx_glr_plot_confusion_matrix_sweet_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/0.3.2/lib/python3.10/site-packages/yellowbrick/classifier/base.py:232: YellowbrickWarning: could not determine class_counts_ from previously fitted classifier .. raw:: html
ConfusionMatrix(ax=<AxesSubplot:title={'center':'XGBClassifier Confusion Matrix'}, xlabel='Predicted Class', ylabel='True Class'>,
                    cmap=<matplotlib.colors.ListedColormap object at 0x7f50a38e81c0>,
                    estimator=XGBClassifier(base_score=None, booster='gbtree',
                                            callbacks=None, colsample_bylevel=None,
                                            colsample_bynode=None,
                                            colsample_bytree=None, device=None,
                                            early_stoppin...
                                            gamma=1.5, grow_policy=None,
                                            importance_type=None,
                                            interaction_constraints=None,
                                            learning_rate=0.07, max_bin=None,
                                            max_cat_threshold=None,
                                            max_cat_to_onehot=None,
                                            max_delta_step=None, max_depth=2,
                                            max_leaves=None, min_child_weight=None,
                                            missing=nan, monotone_constraints=None,
                                            multi_strategy=None, n_estimators=300,
                                            n_jobs=None, num_parallel_tree=None,
                                            objective='multi:softprob', ...))
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.327 seconds) .. _sphx_glr_download_glr_examples_utils_plot_confusion_matrix_sweet.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_matrix_sweet.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_confusion_matrix_sweet.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_confusion_matrix_sweet.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_