Confusion Matrix visualization.
It is recommended to use from_estimator
or from_predictions
to create a ConfusionMatrixDisplay
. All parameters are stored as attributes.
For general information regarding scikit-learn
visualization tools, see the Visualization Guide. For guidance on interpreting these plots, refer to the Model Evaluation Guide.
Confusion matrix.
Display labels for plot. If None, display labels are set from 0 to n_classes - 1
.
Image representing the confusion matrix.
Array of matplotlib axes. None
if include_values
is false.
Axes with confusion matrix.
Figure containing the confusion matrix.
Examples
>>> import matplotlib.pyplot as plt >>> from sklearn.datasets import make_classification >>> from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay >>> 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) >>> predictions = clf.predict(X_test) >>> cm = confusion_matrix(y_test, predictions, labels=clf.classes_) >>> disp = ConfusionMatrixDisplay(confusion_matrix=cm, ... display_labels=clf.classes_) >>> disp.plot() <...> >>> plt.show()
Plot Confusion Matrix given an estimator and some data.
For general information regarding scikit-learn
visualization tools, see the Visualization Guide. For guidance on interpreting these plots, refer to the Model Evaluation Guide.
Added in version 1.0.
Fitted classifier or a fitted Pipeline
in which the last estimator is a classifier.
Input values.
Target values.
List of labels to index the confusion 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.
Either to normalize the counts display in the matrix:
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.
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.
Axes object to plot on. If None
, a new figure and axes is created.
Whether or not to add a colorbar to the plot.
Dict with keywords passed to matplotlib.pyplot.imshow
call.
Dict with keywords passed to matplotlib.pyplot.text
call.
Added in version 1.2.
ConfusionMatrixDisplay
Examples
>>> import matplotlib.pyplot as plt >>> from sklearn.datasets import make_classification >>> from sklearn.metrics import ConfusionMatrixDisplay >>> 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) >>> ConfusionMatrixDisplay.from_estimator( ... clf, X_test, y_test) <...> >>> plt.show()
For a detailed example of using a confusion matrix to evaluate a Support Vector Classifier, please see Confusion matrix
Plot Confusion Matrix given true and predicted labels.
For general information regarding scikit-learn
visualization tools, see the Visualization Guide. For guidance on interpreting these plots, refer to the Model Evaluation Guide.
Added in version 1.0.
True labels.
The predicted labels given by the method predict
of an classifier.
List of labels to index the confusion 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.
Either to normalize the counts display in the matrix:
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.
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.
Axes object to plot on. If None
, a new figure and axes is created.
Whether or not to add a colorbar to the plot.
Dict with keywords passed to matplotlib.pyplot.imshow
call.
Dict with keywords passed to matplotlib.pyplot.text
call.
Added in version 1.2.
ConfusionMatrixDisplay
Examples
>>> import matplotlib.pyplot as plt >>> from sklearn.datasets import make_classification >>> from sklearn.metrics import ConfusionMatrixDisplay >>> 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) >>> y_pred = clf.predict(X_test) >>> ConfusionMatrixDisplay.from_predictions( ... y_test, y_pred) <...> >>> plt.show()
Plot visualization.
Includes values in confusion matrix.
Colormap recognized by matplotlib.
Rotation of xtick labels.
Format specification for values in confusion matrix. If None
, the format specification is ‘d’ or ‘.2g’ whichever is shorter.
Axes object to plot on. If None
, a new figure and axes is created.
Whether or not to add a colorbar to the plot.
Dict with keywords passed to matplotlib.pyplot.imshow
call.
Dict with keywords passed to matplotlib.pyplot.text
call.
Added in version 1.2.
ConfusionMatrixDisplay
Returns a ConfusionMatrixDisplay
instance that contains all the information to plot the confusion matrix.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4