Hướng dẫn dùng confusionmatrixdisplay python
Confusion Matrix visualization. It is recommend to use Read more in the User Guide. Parameters:confusion_matrixndarray of shape (n_classes, n_classes)Confusion matrix. display_labelsndarray of shape (n_classes,), default=NoneDisplay labels for plot. If None, display labels are set
from 0 to Image representing the confusion matrix. text_ndarray of shape (n_classes, n_classes), dtype=matplotlib Text, or NoneArray of matplotlib axes. Axes with confusion matrix. figure_matplotlib FigureFigure 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() Methods
Plot Confusion Matrix given an estimator and some data. Read more in the User Guide. New in version 1.0. Parameters:estimatorestimator instanceFitted classifier or a fitted
Input values. yarray-like of shape (n_samples,)Target values. labelsarray-like of shape (n_classes,), default=NoneList of labels to index the confusion matrix. This may be used to reorder or select a subset of labels. If Sample weights. normalize{‘true’, ‘pred’, ‘all’}, default=NoneEither to normalize the counts display in the matrix:
Target names used for plotting. By default, Includes values in confusion matrix. xticks_rotation{‘vertical’, ‘horizontal’} or float, default=’horizontal’Rotation of xtick labels. values_formatstr, default=NoneFormat specification for values in confusion matrix. If Colormap recognized by matplotlib. Axes object to plot on. If Whether or not to add a colorbar to the plot. im_kwdict, default=NoneDict with keywords passed to 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()classmethodfrom_predictions(y_true, y_pred, *, labels=None, sample_weight=None, normalize=None, display_labels=None, include_values=True, xticks_rotation='horizontal', values_format=None, cmap='viridis', ax=None, colorbar=True, im_kw=None)[source]¶ Plot Confusion Matrix given true and predicted labels. Read more in the User Guide. New in version 1.0. Parameters:y_truearray-like of shape (n_samples,)True labels. y_predarray-like of shape (n_samples,)The
predicted labels given by the method List of labels to index the confusion matrix. This may be used to reorder or select a subset of labels. If Sample weights. normalize{‘true’, ‘pred’, ‘all’}, default=NoneEither to normalize the counts display in the matrix:
Target names used for plotting. By default, Includes values in confusion matrix. xticks_rotation{‘vertical’, ‘horizontal’} or float, default=’horizontal’Rotation of xtick labels. values_formatstr, default=NoneFormat specification for values in confusion matrix. If Colormap recognized by matplotlib. axmatplotlib Axes, default=NoneAxes object to plot on. If Whether or not to add a colorbar to the plot. im_kwdict, default=NoneDict with keywords passed to 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(*, include_values=True, cmap='viridis', xticks_rotation='horizontal', values_format=None, ax=None, colorbar=True, im_kw=None)[source]¶ Plot visualization. Parameters:include_valuesbool, default=TrueIncludes 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=NoneFormat specification for values in confusion matrix. If Axes object to plot on. If Whether or not to add a colorbar to the plot. im_kwdict, default=NoneDict with keywords passed to ConfusionMatrixDisplay Examples using |