March 2020
Intermediate to advanced
366 pages
9h 8m
English
A confusion matrix is a 2D matrix of size equal to (num_classes, num_classes), where the rows correspond to the predicted class labels, and the columns correspond to the actual class labels. Then, the [r,c] matrix element contains the number of samples that were predicted to have label r, but in reality, have label c. Having access to a confusion matrix will allow us to calculate precision and recall.
Now, let's implement a very simple way to calculate the confusion matrix. Similar to accuracy, we create a function with the same arguments, so it's easy to reuse, by following the next steps: