So now let's take a look at creating our confusion matrix.
So to do that, we just have to import the confusion matrix function here from scale and what metrics
we also import number, which we did previously.
But will let's do it again just for some consistency in case you want to extract this block of good
for future use.
So all we're doing here, we're taking steps, reshaping it again and passing it on input into our AMAX
function to get the maximum, to get a class of the maximum probability, then so that gives us now
all our predictions.
So that's why we feed it into a model that predicts excess to get them predictions here.
So no, we have no predictions why we have all grown short levels, whitest.
We just input them into the confusion matrix function and run this.
And it should give us that table that we saw below and hopefully remember how to interpret this.
This is an example of an image I can show you.
So these here are the predicted levels a top rule here.
These here the ground should labels, so you can see for all the ground truth labels that the Label
Zero is predicted in nine hundred and seventy seven times that it was zero.
One time it predicted it was a six or seven and eight and so on.
And you can see the ones I've circled here, the ones where it's classifying like this here, classifying
seven as 2s.
In that case, where is that here?
That's here.
It's 11.
So you can see when the ground shoot was a seven hour model predicted that it was a two 11 times.
So this is in from this table here.
This is this is the actual results for the model that we predicted above.
So you can see this model isn't performing that well.
You can see there's a lot of mistakes going on over here as well as of here.
And what what it says here is 28.
Let's take a look at that one.
This would be the zero one two three four.
So of Class four, twenty times, it's predicting it to be a nine.
Actually, it's not good, but that's OK.
We can do better, for sure.
So here's a more guess some could that have got gotten off the internet?
That basically allows us to plot a much nicer looking confusion matrix.
We don't have to go through this good because it can be quite exhaustive to go through that.
So this is run that function.
This is to plot confusion matrix.
These are the inputs.
It takes some default values.
So what we need to do is just input the confusion matrix and the target names.
And so we get a confusion matrix again from our scaling function.
Target names are basically the range of names is in.
In this case, it's zero to nine.
So we just generated using this range function and convert it into a list and we just use a function
plot confusion matrix here, where the confusion matrix and the target names.
And it gives us this nice, colorful color gradient output that we can use to visually assess performance
better.
So that's OK footwork, and this is just a nicer way to present it if you want to present it in a more
professional manner, and it gives you a summary of the accuracy below.
So now let's take a look at our poor class accuracy.
Here's a fairly simple way to get this there are many different ways you can probably get this as well.
You can just use our imagination if you've got good numbers, skills or panda's skills, you can easily
just manipulate the prediction or put results and compare it to the white test and generate your 1Q
report.
So what we're doing here, in this case, we're taking the confusion matrix output, and we're taking
that diagonal here.
That's this diagonal one at a time.
Well, one of the time we're taking the whole matrix here and then dividing it by the sum.
That's a number that's a total number across each row, and that gives us class accuracy.
So we just enumerate we just looked through the output of this matrix because it's going to be in.
It's going to be one by one for each class, and we'll just print the accuracy below.
So you can see now let's run this.
You can see the accuracy for each class right here.
So you can see it's doing fairly well for zeros and ones.
However, it's doing a bit more poorly for fives, as well as tourists and nines, to an extent.
So now let's take a look at the classification report.
So you may remember the classification report gives us summary of Precision Recall F1 score, which
was a combination of both precision and recall, as well as the support, which basically is sum of
the number of images in that class.
So to do that, it's quite simple.
Again, you just import classification report from schooland dot matrix.
Then you take the lightest test is a drunkard labels for test data set.
These are the predictions when we feed excess into a model.
So we have white bread, which we have from above before and we run this.
And this gives us a nice little confusion.
Sorry, old classification matrix right here and in.
Yes, you forgot how to interpret these things.
Interpret, recall, recall and remember the actual true positives.
How many, how many, how many times the classifier predicted that class, as well as precision, which
is a number of correct predictions over how many occurrences of a class within the test dataset?
So he can use this graph here.
These images here to understand properly what recall is and what precision is, as well as what what
a higher recall means with little precision.
Well, low recall means with high precision.
So that's why I find these notebooks a very good resources for learning these things.
I'll try to put as much notes and comments in accord to help you guys understand.
So hopefully that was a useful lesson and we'll stop there and I will do the same thing in PyTorch.
So stay tuned for that lesson.
Thank you.