sklearn.metrics.multilabel_confusion_matrix(y_true, y_pred, *, sample_weight=None, labels=None, samplewise=False)
Compute class-wise (default) or sample-wise multi-label confusion matrix
When calculating class-wise multi_confusion, the input y_true and y_pred shape is (n_samples, n_labels) (multi-class multi-label case) or (n_samples,) (multi-class single-label case), and the output multi_confusion shape is (n_labels, 2, 2)
The above n_labels is the number of categories.
When calculating sample-wise multi_confusion, the input y_true and y_pred shape is (n_samples, n_labels) (multi-class multi-label case) or (n_samples,) (multi-class single-label case), and the output multi_confusion shape is (n_samples, 2, 2)
example: multi-class single-label >>> import numpy as np >>> from sklearn.metrics import multilabel_confusion_matrix >>> y_true = np.array([[1, 0, 1], ... [0, 1, 0]]) >>> y_pred = np.array([[1, 0, 0], ... [0, 1, 1]]) >>> multilabel_confusion_matrix(y_true, y_pred) array([[[1, 0], [0, 1]], [[1, 0], [0, 1]], [[0, 1], [1, 0]]])
multi-class single-label >>> y_true = ["cat", "ant", "cat", "cat", "ant", "bird"] >>> y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"] >>> multilabel_confusion_matrix(y_true, y_pred, ... labels=["ant", "bird", "cat"]) array([[[3, 1], [0, 2]], [[5, 0], [1, 0]], [[2, 1], [1, 2]]])
reference:
sklearn.metrics.confusion_matrix — scikit-learn 1.1.1 documentation