Welcome back.
And in the last video we saw how to create a confusion matrix with C bonds heat map function.
But right now our confusion matrix using Seabourn is not really offering much like its blank.
Better off using cross tab up here.
But if we wanted to make it a bit more visual what we might do is add some information to this and the
function ize it because if we want to plot multiple confusion matrix it's good to have it in a function.
So let's make it plot com format and we'll we'll pass it to confusion matrix with the very name compliment
and then we'll put in a little R doctoring.
Then we want to be great communicators here.
Plot the confusion matrix using C Bond's heat map something not in simple again we could upgrade this
to say what actual confusion matrix is but it's kind of intuitive anyway.
Big acts want to set up a plot plot BLT some plots we want fig size 3 by 3 x equals s and s dot heat
map.
We've seen this we're gonna pass it confirm that and then this is where we can add some information.
So we want a not short for annotate equals true.
We want to go.
Here is a comment annotate the boxes with com from that info.
Beautiful.
And then we want to see bar equals false.
Now these are parameters of the heat map function.
You can see those in the documentation here seaborne dot heat map or as always by pressing shift tab
they're wonderful and then we're going to add some communication.
So BLT dot ex label is gonna be the true label and then pale T dot why label is going to be the predicted
label wonderful.
Put a little semicolon there and then we'll call plot com.
Matt.
Matt how does this look.
All right we're getting some communication we're getting somewhere.
But why are our numbers appearing literally off the grid.
Well how would you figure this out if you ran into these sort of problem.
What would you do.
Well I'll tell you what I did.
I went me as I went seaborne numbers not appearing in square on heat map something like that.
There we go.
S.A. heat he met top and bottom boxes are cut off.
Now this is one of the gate hub issues with seaborne.
Let's zoom in a little bit with seaborne zero point nine point zero and map plot lib three point one
point one The topmost and bottom most row of boxes in seaborne plot are cut off.
Yes Zero's getting cut off their
so this is a big version of heat map and so this is getting cut off just like ours.
I see.
All right.
What can we do.
This was a map plot lib regression introduced in three point one which has been fixed in three point
one point two still forthcoming.
Okay for now the fix is to downgrade map plot lib to a private version.
All right.
So there's a few fixes here.
And so what I've done.
We're not gonna go through it all but essentially that's the process I took right.
Was I just searched the error that I had.
And then you come across resources like this and you read through them and you go okay there's some
potential fixes this might be my issue.
In my case my issue is that I'm using Matt pot lib 3.0 one point one but after a little bit more digging
I found a work around that you can do without having to downgrade Matt pot legal or wait for the update
to come through and that's fix the broken annotations this happened in Fort Lee but three point one
point one.
By the time you try out this right.
This function may work perfectly for you because you'd be using that pot lib three point one point to
where the error gets fixed.
But if not this is a workaround right.
That's what we are as engineers.
We're looking for solutions to our problems not necessarily work arounds but solutions to our problems.
This is why Lim so this is going to say bottom top X equals get Y limitation so we're getting the limitations
about y axis is here and then we're gonna go X dot set y lim gonna go bottom plus zero point five and
then top minus zero point five.
We can take out the semicolon here put it here so what is this doing.
First of all let's see it.
Wonderful.
So this is just saying hey set bottom and top to the current Y limitations of our accesses and then
reset them to b bottom plus O point five so it's gonna move that number up like a comment at this it's
gonna move that number up and then it's going to bring this number down or these two numbers down.
So that's all that's happening in these two lines.
And that was a fix again I found through a little bit of searching searching up something like that
seaborne heat map plot numbers not appearing in the right way.
Now that's looking a bit more like what we used in our confusion matrix anatomy.
Beautiful.
And now that's looking like exactly something you can start to share.
You could even start to try and customize these labels here so that someone knows what zero is.
Or put a little key here so zero is not heart disease one is heart disease.
You could customize this as much as you want but it's essentially one of the best ways to visualize
a confusion matrix.
Now you might be asking is why do we jump straight to Seabourn instead of using psychic line.
Surely they have a plotting and confusion matrix.
And I thought the same thing too.
But if we look at this if we go from S.K. lone dot matrix import plot confusion matrix and we go plot
confusion matrix pass it out CnF so if we look at is cannot import name plot confusion matrix from psychic
line Why is that.
So we're going here.
So I can't learn plot confusion matrix confusion matrix okay and then we go down here houses happening.
So from S.K. learned dot matrix import plot confusion matrix.
Okay.
We see that they've used the function here and now we click on this SDK lined up matrix plot confusion
matrix.
All right.
So that's what we've done right.
We've imported it from here from SDK lined up matrix import plot confusion matrix yet it still doesn't
work.
This is one of the caveats of using an open source library right is that although psychic line is incredibly
helpful in offering us a bunch of different functions and same goes for any other open source library
there are some cases where certain functions may not work right like this.
We try to import it.
It doesn't work.
So again it's another example of where we've created a solution to our problem.
If we couldn't use psychic loans metrics function plot confusion matrix we build our own.
We use seaborne heat map or we could even just use Panda's cross tab as a prime example of putting on
our engineering hat and figuring things out.
But in essence the main thing to remember with the confusion matrix is it shows you where your model
is getting confused.
If we go back to our anatomy the correct predictions are going to be along the diagonal and the false
negatives and false positives are going to be on either side of that diagonal.
So with that being said we've covered a fair few things that the confusion matrix.
Let's have a look at one final classification metric which is also really important and that is called
the classification report.
Changes in a marked down and we'll finish the video there.
We'll see in the next one.