plot_classifier_eval#
- scikitplot.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)#
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_true (array-like, shape (n_samples,)) – Ground truth (correct) target values.
y_pred (array-like, shape (n_samples,)) – Predicted target values from the classifier.
labels (list 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.
digits (int, optional, default=3) – Number of digits for formatting floating point values in the plots.
title (string, optional, default='train') – Title of the generated plot.
ax (list 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)]
fig (matplotlib.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.
figsize (tuple of int, optional, default=(8, 3)) – Tuple denoting figure size of the plot, e.g. (8, 3).
title_fontsize (string or int, optional, default="large") – Font size for the plot title. Use e.g. “small”, “medium”, “large” or integer values.
text_fontsize (string or int, optional, default="medium") – Font size for the text in the plot. Use e.g. “small”, “medium”, “large” or integer values.
cmap (None, str or matplotlib.colors.Colormap, optional, default=None) – Colormap used for plotting. Options include ‘viridis’, ‘PiYG’, ‘plasma’, ‘inferno’, etc. See Matplotlib Colormap documentation for available choices. - https://matplotlib.org/stable/users/explain/colors/index.html
x_tick_rotation (int, optional, default=0) –
Rotates x-axis tick labels by the specified angle.
Added in version 0.3.9.
- Returns:
fig – The figure on which the plot was drawn.
- Return type:
Notes
The function generates and displays multiple evaluation plots. Ensure that
y_true
andy_pred
have the same shape and contain valid class labels. Thenormalize
parameter is applicable to the confusion matrix plot. Adjustcmap
andx_tick_rotation
to customize the appearance of the plots.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
)