Plot confusion matrices#

plots inline multiple confusion matrices from selected models

# Author: L.Kouadio
# Licence: BSD-3-clause

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

# 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 ]
[SVC(C=2.0, coef0=0, degree=1, gamma=0.125), LogisticRegression(), RandomForestClassifier(criterion='entropy', max_depth=16, n_estimators=350)]
  • Plot the confusions metrics with the selected estimators

plot_confusion_matrices(fitted_models , Xt, yt)
SVC, LogisticRegression, RandomForestClassifier
  • Plot using the yellowbrick packages

plot_confusion_matrices(fitted_models , Xt, yt, pkg ='yb')
  • SVC Confusion Matrix, LogisticRegression Confusion Matrix, RandomForestClassifier Confusion Matrix
  • plot confusion matrices
  • plot confusion matrices
  • plot confusion matrices
/home/docs/checkouts/readthedocs.org/user_builds/watex/envs/master/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/master/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/master/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 1.197 seconds)

Gallery generated by Sphinx-Gallery