In sklearn.metrics.confusion_matrix(y_true, y_pred), how is the matrix laid out?
Correct answer
D. Rows are the true classes and columns are predicted ones, in label order
19 views
D. Rows are the true classes and columns are predicted ones, in label order
19 views
confusion_matrix returns C[i][j] as the number of samples with true label i and predicted label j, so rows are actual classes and the diagonal counts correct predictions. Reading it transposed is a common error that swaps precision and recall. Pass labels= to fix the order when some classes are missing from a split.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is D? Ask here and get an explanation.