watex.utils.plotutils.plot_confusion_matrix#
- watex.utils.plotutils.plot_confusion_matrix(yt, y_pred, view=True, ax=None, annot=True, **kws)[source]#
plot a confusion matrix for a single classifier model.
- :param ytndarray or Series of length n
An array or series of true target or class values. Preferably, the array represents the test class labels data for error evaluation.
- Parameters
y_pred β ndarray or Series of length n An array or series of the predicted target.
view β bool, default=True Option to display the matshow map. Set to
Falsemutes the plot.annot β bool, default=True Annotate the number of samples (right or wrong prediction ) in the plot. Set
Falseto mute the display.
- param kws: dict,
Additional keyword arguments passed to the function
sckitlearn.metrics.confusion_matrix().
- Returns
mat- confusion matrix bloc matrix
- Example
>>> #Import the required models and fetch a an Ababoost model >>> # 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_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 ='ada' ) >>> pmo.fit(X, y ) >>> print(pmo.estimator_ ) >>> #%% >>> # Predict the score using under the hood the best estimator >>> # for adaboost classifier >>> ypred = pmo.predict(Xt) >>> # now plot the score >>> plot_confusion_matrix (yt , ypred )