DEPRECATED:
Function plot_confusion_matrix
is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: ConfusionMatrixDisplay.from_predictions or ConfusionMatrixDisplay.from_estimator.
Plot Confusion Matrix.
plot_confusion_matrix
is deprecated in 1.0 and will be removed in 1.2. Use one of the following class methods:
from_predictions
or from_estimator
.
Read more in the User Guide.
Parameters:estimatorestimator instanceFitted classifier or a fitted Pipeline
in which the last
estimator is a classifier.
Input values.
Target values.
labelsarray-like of shape [n_classes,], default=NoneList of labels to index the matrix. This may be used to reorder or select a subset of labels. If None
is given, those that
appear at least once in y_true
or y_pred
are used in sorted order.
Sample weights.
normalize{‘true’, ‘pred’, ‘all’}, default=NoneEither to normalize the counts display in the matrix:
display_labelsarray-like of shape [n_classes,], default=None
if
'true'
, the confusion matrix is normalized over the true conditions [e.g. rows];if
'pred'
, the confusion matrix is normalized over the predicted conditions [e.g. columns];if
'all'
, the confusion matrix is normalized by the total number of samples;if
None
[default], the confusion matrix will not be normalized.
Target names used for plotting. By default, labels
will be used if it is defined, otherwise the
unique labels of y_true
and y_pred
will be used.
Includes values in confusion matrix.
xticks_rotation{‘vertical’, ‘horizontal’} or float, default=’horizontal’Rotation of xtick labels.
Format specification for values in confusion matrix. If None
, the format
specification is ‘d’ or ‘.2g’ whichever is shorter.
Colormap recognized by matplotlib.
axmatplotlib Axes, default=NoneAxes object to plot on. If None
, a new figure and axes is created.
Whether or not to add a colorbar to the plot.
New in version 0.24.
Returns:displayConfusionMatrixDisplay
Object that stores computed values.
Examples
>>> import matplotlib.pyplot as plt >>> from sklearn.datasets import make_classification >>> from sklearn.metrics import plot_confusion_matrix >>> from sklearn.model_selection import train_test_split >>> from sklearn.svm import SVC >>> X, y = make_classification[random_state=0] >>> X_train, X_test, y_train, y_test = train_test_split[ ... X, y, random_state=0] >>> clf = SVC[random_state=0] >>> clf.fit[X_train, y_train] SVC[random_state=0] >>> plot_confusion_matrix[clf, X_test, y_test] >>> plt.show[]