plot_classifier_eval#

scikitplot.api.metrics.plot_classifier_eval(y_true, y_pred, *, labels=None, normalize=None, digits=3, title='train', ax=None, fig=None, figsize=(8, 3), title_fontsize='large', text_fontsize='medium', cmap=None, x_tick_rotation=0, **kwargs)[source]#

Generates various evaluation plots for a classifier, including confusion matrix, precision-recall curve, and ROC curve.

This function provides a comprehensive view of a classifier’s performance through multiple plots, helping in the assessment of its effectiveness and areas for improvement.

Parameters:
y_truearray-like, shape (n_samples,)

Ground truth (correct) target values.

y_predarray-like, shape (n_samples,)

Predicted target values from the classifier.

labelslist of string, optional

List of labels for the classes. If None, labels are automatically generated based on the class indices.

normalize{‘true’, ‘pred’, ‘all’, None}, optional

Normalizes the confusion matrix according to the specified mode. Defaults to None.

  • ‘true’: Normalizes by true (actual) values.

  • ‘pred’: Normalizes by predicted values.

  • ‘all’: Normalizes by total values.

  • None: No normalization.

digitsint, optional, default=3

Number of digits for formatting floating point values in the plots.

titlestring, optional, default=’train’

Title of the generated plot.

axlist of matplotlib.axes.Axes, optional, default=None

The axis to plot the figure on. If None is passed in the current axes will be used (or generated if required). Need two axes like [fig.add_subplot(1, 2, 1), fig.add_subplot(1, 2, 2)]

figmatplotlib.pyplot.figure, optional, default: None

The figure to plot the Visualizer on. If None is passed in the current plot will be used (or generated if required).

Added in version 0.3.9.

figsizetuple of int, optional, default=(8, 3)

Tuple denoting figure size of the plot, e.g. (8, 3).

title_fontsizestring or int, optional, default=”large”

Font size for the plot title. Use e.g. “small”, “medium”, “large” or integer values.

text_fontsizestring or int, optional, default=”medium”

Font size for the text in the plot. Use e.g. “small”, “medium”, “large” or integer values.

cmapNone, str or matplotlib.colors.Colormap, optional, default=None

Colormap used for plotting. Options include ‘viridis’, ‘PiYG’, ‘plasma’, ‘inferno’, ‘nipy_spectral’, etc. See Matplotlib Colormap documentation for available choices.

x_tick_rotationint, optional, default=0

Rotates x-axis tick labels by the specified angle.

Added in version 0.3.9.

Returns:
figmatplotlib.figure.Figure

The figure on which the plot was drawn.

Notes

The function generates and displays multiple evaluation plots. Ensure that y_true and y_pred have the same shape and contain valid class labels. The normalize parameter is applicable to the confusion matrix plot. Adjust cmap and x_tick_rotation to customize the appearance of the plots.

References#

Examples

>>> from sklearn.datasets import load_digits as data_10_classes
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.naive_bayes import GaussianNB
>>> import scikitplot as skplt
>>> X, y = data_10_classes(return_X_y=True, as_frame=False)
>>> X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.5, random_state=0)
>>> model = GaussianNB()
>>> model.fit(X_train, y_train)
>>> y_val_pred = model.predict(X_val)
>>> skplt.metrics.plot_classifier_eval(
>>>     y_val, y_val_pred,
>>>     title='val',
>>> );

(Source code, png)

Confusion Matrix