Build a K×K confusion matrix whose row is the true class and whose column is the predicted class:
Cij=n=1∑N1[yn=i and y^n=j]Here, N is the sample count, K is the number of classes, yn is the true label, and y^n is the predicted label. The normalize mode is "none" for counts, "true" for rows summing to one, "pred" for columns summing to one, or "all" for the entire matrix summing to one. A zero row or column remains zero. Return the matrix as a NumPy array.
Input: y_true = [0, 1, 1], y_pred = [0, 1, 0], num_classes = None, normalize = "none"
Output: [[1, 0], [1, 1]]
Explanation: One class-0 sample is correct, while the two class-1 samples split between predictions 0 and 1.
Input: y_true = [0, 1, 1], y_pred = [0, 1, 0], num_classes = None, normalize = "true"
Output: [[1, 0], [0.5, 0.5]]
Flatten each pair into y_true * K + y_pred before calling np.bincount.
Use np.divide(matrix, totals, out=..., where=totals != 0) for safe normalization.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: any
Accepts: string
Build a K×K confusion matrix whose row is the true class and whose column is the predicted class:
Cij=n=1∑N1[yn=i and y^n=j]Here, N is the sample count, K is the number of classes, yn is the true label, and y^n is the predicted label. The normalize mode is "none" for counts, "true" for rows summing to one, "pred" for columns summing to one, or "all" for the entire matrix summing to one. A zero row or column remains zero. Return the matrix as a NumPy array.
Input: y_true = [0, 1, 1], y_pred = [0, 1, 0], num_classes = None, normalize = "none"
Output: [[1, 0], [1, 1]]
Explanation: One class-0 sample is correct, while the two class-1 samples split between predictions 0 and 1.
Input: y_true = [0, 1, 1], y_pred = [0, 1, 0], num_classes = None, normalize = "true"
Output: [[1, 0], [0.5, 0.5]]
Flatten each pair into y_true * K + y_pred before calling np.bincount.
Use np.divide(matrix, totals, out=..., where=totals != 0) for safe normalization.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: any
Accepts: string