sklearn.metrics.ConfusionMatrixDisplay

class sklearn.metrics.ConfusionMatrixDisplay(confusion_matrix, display_labels)[source]

Confusion Matrix visualization.

It is recommend to use plot_confusion_matrix to create a ConfusionMatrixDisplay. All parameters are stored as attributes.

Read more in the User Guide.

Parameters
confusion_matrixndarray of shape (n_classes, n_classes)

Confusion matrix.

display_labelsndarray of shape (n_classes,)

Display labels for plot.

Attributes
im_matplotlib AxesImage

Image representing the confusion matrix.

text_ndarray of shape (n_classes, n_classes), dtype=matplotlib Text, or None

Array of matplotlib axes. None if include_values is false.

ax_matplotlib Axes

Axes with confusion matrix.

figure_matplotlib Figure

Figure containing the confusion matrix.

Methods

plot(self[, include_values, cmap, …])

Plot visualization.

__init__(self, confusion_matrix, display_labels)[source]

Initialize self. See help(type(self)) for accurate signature.

plot(self, include_values=True, cmap='viridis', xticks_rotation='horizontal', values_format=None, ax=None)[source]

Plot visualization.

Parameters
include_valuesbool, default=True

Includes values in confusion matrix.

cmapstr or matplotlib Colormap, default=’viridis’

Colormap recognized by matplotlib.

xticks_rotation{‘vertical’, ‘horizontal’} or float, default=’horizontal’

Rotation of xtick labels.

values_formatstr, default=None

Format specification for values in confusion matrix. If None, the format specification is ‘.2g’.

axmatplotlib axes, default=None

Axes object to plot on. If None, a new figure and axes is created.

Returns
displayConfusionMatrixDisplay