Note
Go to the end to download the full example code or to run this example in your browser via Binder
Plot confusion matrix sweet#
plots a confusion matrix using the ‘yellowbrick’ package.
# Author: L.Kouadio
# Licence: BSD-3-clause
- Import the required models and fetch an extreme gradient boosting
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 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_
XGBClassifier(base_score=None, booster='gbtree', callbacks=None,
colsample_bylevel=None, colsample_bynode=None,
colsample_bytree=None, early_stopping_rounds=None,
enable_categorical=False, eval_metric=None, feature_types=None,
gamma=1.5, gpu_id=None, 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,
n_estimators=300, n_jobs=None, num_parallel_tree=None,
objective='multi:softprob', predictor=None, ...)
Predict the score using under the hood the best estimator for adaboost classifier
ypred = pmo.predict(Xt)
# now plot the score
plot_yb_confusion_matrix (pmo.XGB.best_estimator_, Xt, yt )

/home/docs/checkouts/readthedocs.org/user_builds/watex/envs/0.2.4/lib/python3.10/site-packages/yellowbrick/classifier/base.py:232: YellowbrickWarning:
could not determine class_counts_ from previously fitted classifier
Total running time of the script: ( 0 minutes 0.379 seconds)