22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Output

array([[ 7, 2],

[ 1, 10]])

All 20 points in our validation set are accounted for. There are three misclassified

points: one false negative and two false positives, just like in the figure above. I

chose to move the blue points (positive) below the line to match Scikit-Learn’s

convention for the confusion matrix.

Confusion matrices are already confusing enough on their own,

but what’s even worse is that you’ll find all sorts of layouts

around. Some people list positives first and negatives last. Some

people even flip actuals and predicted classes, effectively

transposing the confusion matrix. Make sure to always check the

layout before drawing conclusions from matrices you see "in the

wild."

To make your life, and mine, simpler, I am just sticking with Scikit-

Learn’s convention throughout this book.

There is one more thing I hope you noticed already: The confusion matrix depends

on the threshold. If you shift the threshold along the probability line, you’ll end up

changing the number of points in each quadrant.

There are many confusion matrices, one for each threshold.

Moreover, different confusion matrices mean different metrics. We need the

individual components of the confusion matrix, namely, TN, FP, FN, and TP, to

construct those metrics. The function below splits the confusion matrix

accordingly:

244 | Chapter 3: A Simple Classification Problem

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!