Taking the mystery out of sklearn’s confusion_matrix and classification_report

Crystal X
4 min readJul 30, 2021

When making predictions on data, it is important to evaluate the metrics involved in the prediction as a point to endeavour to correct as many errors as possible. One evaluation metric that is quite straightforward is sklearn’s confusion matrix. The diagram below shows how a binary confusion matrix operates. Ideally all of the positives would be true and all of the negatives would also be true, with no false positives and no false negatives:-

In order to illustrate how to use sklearn’s confusion_matrix, I have written a program with sklearn’s make_classifier function. Instead of creating a binary classifier, I decided to spice things up a bit by giving the label three classes.

I wrote the program in Google Colab, which is Google’s free online Jupyter Notebook. The great thing about Google Colab is the fact that the notebooks that are created can be saved in the Google drive, which is also free. There are a number of other Jupyter Notebooks also available, such as www.jupyter.org, but I have never created a notebook using this site so I cannot verify the quality of this product.

--

--

Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.