‫Welcome back.
‫And in the last video, we finished off saying the next classification model evaluation metric we're
‫going to use is a confusion matrix.
‫Now, if you're confused about the name confusion matrix, don't worry, it will make sense after we
‫go through it.
‫So a confusion matrix, let's define it, is a quick way to compare the labels a model predicts and
‫the actual labels it was supposed to predict.
‫Now, in essence.
‫Giving you an idea of where the model is getting confused.
‫Beautiful.
‫Now, again, if it's still confusing, don't worry.
‫Let's have a look.
‫That's what we always do, right?
‫We prefer to get hands on.
‫So from Skyline, we're going to go from the Matrix module.
‫We'll import confusion matrix.
‫And now we can create a confusion matrix by making some predictions.
‫We've seen how to do this with the predict function.
‫We're going to do that on the test data set.
‫And then we're going to pass confusion matrix.
‫The function confusion matrix y tests are the true labels and the predictions.
‫So this is the crux of what basically all evaluation metrics are doing, right?
‫They're comparing the true labels with the predictions and giving us some insights on that comparison.
‫And so if we hit shift into.
‫Oh, get no Ryback.
‫What does this even mean?
‫Just for numbers.
‫Hmm.
‫Again, this is probably another thing that is easier to understand when it's visualized.
‫One way to do so is visualize confusion matrix with PD Cross tab.
‫So let's see it in action.
‫So we're going to go PD for Pandas Cross Tab, which is going to compare two different things.
‫Y test.
‫We want to compare the Y test labels.
‫Again, just another comparison between the true labels and the predictions y test y spreads and we're
‫going to pass at row names is actual labels.
‫Column names is.
‫Can you guess?
‫If not, that's fine.
‫No, this is short for code names.
‫This will be row names.
‫So we don't need that essay.
‫This is going to be.
‫Predicted labels.
‫Wonderful.
‫So what is going on here?
‫Well, because we are comparing.
‫The true labels versus the predicted labels.
‫This is what our cross tab of the confusion matrix is showing us.
‫So where our predicted labels, where our model has predicted zero one and our actual labels.
‫So here the rows are the actual labels and the columns are the predicted labels.
‫So in our case, where the actual label is zero and the predicted label is zero, we have 22 examples.
‫And then where the predicted label is one and the actual label is one, we have 24 examples and if we
‫totaled all of these up before we check out the other 222 plus seven plus eight plus 24, that's going
‫to give us 61.
‫And then if we remind ourselves of how many predictions we've made, there's 61 Y because there's 61
‫examples in the test set.
‫Okay.
‫So what are these two here?
‫Right.
‫So this is let's read it out.
‫So we got predicted label where the model is predicted one, but the actual label was zero.
‫Okay.
‫So that's a false positive.
‫So there's seven of those and now we have a predicted label of zero, but the actual label is one.
‫So that's eight examples of that.
‫So that's eight false negatives.
‫And so hence this is where the confusion matrix or the word confusion comes into confusion matrix.
‫These examples here, this diagonal is where our model is getting confused, aka predicting zero, where
‫the actual label was one or predicting one, where the actual label was zero.
‫And a confusion matrix.
‫We look here with the model, got the samples right is on the diagonal so this here so if we come to
‫our confusion matrix anatomy now we're going to replicate this in the next video.
‫It's our confusion matrix anatomy we see correct here.
‫There's a diagonal.
‫So this is true positives.
‫True negatives.
‫False negatives is over here.
‫So on the right side of the confusion matrix and the false positives is down here.
‫Why is it a false negative?
‫Well, the predicted label is zero.
‫Right.
‫And the model has the true label is actually one.
‫And this is a false positive because the model is predicted one and the true label is zero.
‫And we've seen this before.
‫What a true positive, a false positive.
‫A true negative and a false negative is.
‫So how would we replicate something like this, which is, again, a little bit more visual than our
‫cross tab?
‫One way to do so.
‫Is with.
‫Let's make a comment here.
‫Make our confusion matrix more visual with C Bourne's heat map.
‫Huh?
‫We going?
‫Daniel, what the hell is seaborne?
‫Well, if we go here.
‫Seaborne heat map.
‫This is what I do.
‫Whenever I don't know something, I go seaborne heat map and look at seaborne.
‫You might be asking what even is seaborne?
‫Seaborne heat map plot rectangular data as a color encoded matrix.
‫All right, well, I'll give you the nuts and bolts.
‫Seaborne is a visualization library that is built on top of map plot lib, and it's pretty relatively
‫easy to use, but we're going to mostly just take care of the heat map function.
‫So let's see it.
‫So import seaborne as Psns and then we're going to go set the font scale of seaborne because it can
‫be a bit smaller, set the font scale and we want psns don't set we want font scale.
‫This is one of the easiest ways to visualize a confusion matrix other than a cross tab.
‫So we're going to go create a confusion matrix.
‫We're going to come from that short for confusion matrix as we like to minimize the amount of keystrokes
‫that we take, we test y spreads, pass it the test and predictions, just like we've done up here.
‫And then we're going to plot it using seaborne sas dot heat map conf map.
‫Oh.
‫What?
‫Module not found error.
‫Drat.
‫We can't use Seabourn.
‫No, I'm kidding.
‫So the reason why this module is not found is because you remember right back in the start when we created
‫our environment using Conda?
‫Well, when we did that, we didn't install Seabourn.
‫And because Seabourn is built on top of map plot lib, we do have map plot lib, but we don't have Seabourn,
‫we have pandas, we have Cyclone, we have Jupiter, but we're missing Seabourn.
‫So how would you go about installing a module into your condor environment?
‫What we've got running in our terminal, right?
‫So this is our condor environment running in our terminal.
‫This is what's serving up our Jupyter Notebook server.
‫How do you think you would install it?
‫So one way would be to go to terminal, start a new window.
‫We might go CD desktop email course where my environment is stored, sample project or zoom in here
‫so you can see it.
‫Sample Project LRS So we've got our environment here and then if we go condemn list.
‫Wonderful.
‫And then if we wanted to activate it, we could go conda activate.
‫We want our sample project.
‫I'll copy and paste that.
‫Then I could go conda install Seabourn.
‫That's one option I won't head into because I'm going to show you the other option.
‫I'm going to show you how you can do it right within a Jupyter Notebook.
‫This is a little bonus tip, right?
‫We're doing this during a classification model evaluation video, but because we want to use Seabourn,
‫let's see how we can do it from within a Jupyter Notebook.
‫So this is something you might try whenever you get this module not found error.
‫So you come across some code or you come across a function that you want to use from a library you don't
‫have installed.
‫This is how you can do it from within a Jupyter notebook to install it into the environment so it's
‫ready to go.
‫So after running this cell here, we're going to be able to use this cell.
‫If everything works.
‫A plan.
‫Yes.
‫Prefix.
‫So what this is saying is we're importing CIS.
‫This is going to let us access our system aka our computer, and then we're running this bang function,
‫which is just a way of telling Jupyter to run a bash command.
‫So as if we did the same command here, LZ.
‫Now, if we run bang LZ here, it's going to show us the exact same output.
‫But just from within a Jupyter notebook, we'll get rid of that cell.
‫We don't need it.
‫And we're going to install we're going to pass on to install.
‫Yes.
‫And prefix we've seen prefix.
‫When we're setting up our environment, we're going to go cis prefix.
‫Prefix is just another word for path name a.k.a.
‫This thing here.
‫Path name.
‫And then we're going to go Seabourn.
‫So fingers crossed we run this sell.
‫We should install Seabourn and then we should be able to plot our confusion matrix using C Bourne's
‫heatmap function.
‫So let's shift and enter.
‫Hello again.
‫Some loading.
‫Beautiful.
‫This is telling us what it's going to do.
‫A newer version of Condor exist.
‫Thank you.
‫Package plan added slash updated specs.
‫Seabourn Yep.
‫The following new packages will be installed.
‫Yep.
‫Patsy Seaborne starts models preparing transaction.
‫Dun dun dun.
‫Tick.
‫Moment of truth.
‫Might take a little while to impart.
‫Oh, there we go.
‫But it's not really offering much.
‫Hmm.
‫Why is that?
‫We go back to our keynote to see our confusion matrix anatomy.
‫We want it to look a bit bit more like this, right?
‫To get some numbers on there.
‫Now, why isn't this offering that?
‫Well, let's pause a video there.
‫We'll continue on fixing up our confusion matrix in the next video.
‫See how we can get some numbers on there.
‫But take a little note of this one here.
‫It'll be in the example code reference that you can use.
‫But this is how.
‫You can install how to install a conda package.
‫From a jupyter notebook.
‫Into the current environment.
‫And then you just put the package over here.
‫All right.
‫Let's take a quick break.
‫There was a lot to cover in that video.
‫I'll see you in the next one.