extract_confusion_matrix function

Internal function to extract the confusion matrix.