watex.utils.plot_confusion_matrices#
- watex.utils.plot_confusion_matrices(clfs, Xt, yt, annot=True, pkg=None, normalize='true', sample_weight=None, encoder=None, fig_size=(22, 6), savefig=None, subplot_kws=None, **scorer_kws)[source]#
Plot inline multiple model confusion matrices using either the sckitlearn or ‘yellowbrick’
- Parameters:
clfs (list of classifier estimators) – A scikit-learn estimator that should be a classifier. If the model is not a classifier, an exception is raised. Note that the classifier must be fitted beforehand.
Xt (ndarray or DataFrame of shape (M X N)) – A matrix of n instances with m features. Preferably, matrix represents the test data for error evaluation.
yt (ndarray of shape (M, ) or Series oF length (M, )) – An array or series of target or class values. Preferably, the array represent the test class labels data for error evaluation.
pkg (str, optional , default ='sklearn') – the library to handle the plot. It could be ‘yellowbrick’. The basic confusion matrix is handled by the scikit-learn package.
normalize ({'true', 'pred', 'all'}, default=None) – Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population. If None, confusion matrix will not be normalized.
sample_weight (array-like of shape (n_samples,), default=None) – Sample weights.
encoder (dict or LabelEncoder, default: None) – A mapping of classes to human readable labels. Often there is a mismatch between desired class labels and those contained in the target variable passed to
fit()orscore(). The encoder disambiguates this mismatch ensuring that classes are labeled correctly in the visualization.
- annot: bool, default=True
Annotate the number of samples (right or wrong prediction ) in the plot. Set
Falseto mute the display.- fig_sizetuple (width, height), default =(8, 6)
the matplotlib figure size given as a tuple of width and height
- savefig: str, default =None ,
the path to save the figures. Argument is passed to matplotlib.Figure class.
Examples
>>> 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_ ] >>> models [SVC(C=2.0, coef0=0, degree=1, gamma=0.125), LogisticRegression(), RandomForestClassifier(criterion='entropy', max_depth=16, n_estimators=350)] >>> # now fit all estimators >>> fitted_models = [model.fit(X, y) for model in models ] >>> plot_confusion_matrices(fitted_models , Xt, yt)