1 00:00:00,390 --> 00:00:01,530 Welcome back. 2 00:00:01,560 --> 00:00:07,310 And in the last video we saw how to create a confusion matrix with C bonds heat map function. 3 00:00:07,320 --> 00:00:13,740 But right now our confusion matrix using Seabourn is not really offering much like its blank. 4 00:00:13,870 --> 00:00:16,350 Better off using cross tab up here. 5 00:00:16,440 --> 00:00:21,600 But if we wanted to make it a bit more visual what we might do is add some information to this and the 6 00:00:21,600 --> 00:00:26,630 function ize it because if we want to plot multiple confusion matrix it's good to have it in a function. 7 00:00:26,790 --> 00:00:34,220 So let's make it plot com format and we'll we'll pass it to confusion matrix with the very name compliment 8 00:00:35,130 --> 00:00:38,260 and then we'll put in a little R doctoring. 9 00:00:38,580 --> 00:00:40,620 Then we want to be great communicators here. 10 00:00:40,620 --> 00:00:50,110 Plot the confusion matrix using C Bond's heat map something not in simple again we could upgrade this 11 00:00:50,110 --> 00:00:54,520 to say what actual confusion matrix is but it's kind of intuitive anyway. 12 00:00:54,530 --> 00:01:08,680 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 13 00:01:08,680 --> 00:01:08,910 map. 14 00:01:08,920 --> 00:01:13,420 We've seen this we're gonna pass it confirm that and then this is where we can add some information. 15 00:01:13,420 --> 00:01:18,760 So we want a not short for annotate equals true. 16 00:01:18,890 --> 00:01:19,570 We want to go. 17 00:01:19,580 --> 00:01:27,160 Here is a comment annotate the boxes with com from that info. 18 00:01:27,250 --> 00:01:28,360 Beautiful. 19 00:01:28,360 --> 00:01:31,240 And then we want to see bar equals false. 20 00:01:31,240 --> 00:01:33,890 Now these are parameters of the heat map function. 21 00:01:33,940 --> 00:01:40,450 You can see those in the documentation here seaborne dot heat map or as always by pressing shift tab 22 00:01:40,660 --> 00:01:44,960 they're wonderful and then we're going to add some communication. 23 00:01:44,980 --> 00:01:56,710 So BLT dot ex label is gonna be the true label and then pale T dot why label is going to be the predicted 24 00:01:56,950 --> 00:01:59,810 label wonderful. 25 00:02:00,030 --> 00:02:03,600 Put a little semicolon there and then we'll call plot com. 26 00:02:03,760 --> 00:02:05,320 Matt. 27 00:02:06,250 --> 00:02:11,850 Matt how does this look. 28 00:02:11,990 --> 00:02:14,360 All right we're getting some communication we're getting somewhere. 29 00:02:14,390 --> 00:02:17,060 But why are our numbers appearing literally off the grid. 30 00:02:17,840 --> 00:02:21,920 Well how would you figure this out if you ran into these sort of problem. 31 00:02:22,100 --> 00:02:23,510 What would you do. 32 00:02:23,510 --> 00:02:24,590 Well I'll tell you what I did. 33 00:02:24,950 --> 00:02:35,900 I went me as I went seaborne numbers not appearing in square on heat map something like that. 34 00:02:35,940 --> 00:02:36,450 There we go. 35 00:02:36,460 --> 00:02:39,180 S.A. heat he met top and bottom boxes are cut off. 36 00:02:39,190 --> 00:02:44,550 Now this is one of the gate hub issues with seaborne. 37 00:02:44,550 --> 00:02:49,440 Let's zoom in a little bit with seaborne zero point nine point zero and map plot lib three point one 38 00:02:49,440 --> 00:02:55,220 point one The topmost and bottom most row of boxes in seaborne plot are cut off. 39 00:02:55,290 --> 00:02:57,180 Yes Zero's getting cut off their 40 00:03:00,270 --> 00:03:05,370 so this is a big version of heat map and so this is getting cut off just like ours. 41 00:03:05,370 --> 00:03:07,010 I see. 42 00:03:07,140 --> 00:03:07,570 All right. 43 00:03:07,570 --> 00:03:09,060 What can we do. 44 00:03:09,270 --> 00:03:13,980 This was a map plot lib regression introduced in three point one which has been fixed in three point 45 00:03:13,980 --> 00:03:16,320 one point two still forthcoming. 46 00:03:16,320 --> 00:03:20,330 Okay for now the fix is to downgrade map plot lib to a private version. 47 00:03:20,340 --> 00:03:20,750 All right. 48 00:03:20,780 --> 00:03:22,040 So there's a few fixes here. 49 00:03:22,050 --> 00:03:23,330 And so what I've done. 50 00:03:23,430 --> 00:03:27,600 We're not gonna go through it all but essentially that's the process I took right. 51 00:03:27,720 --> 00:03:30,470 Was I just searched the error that I had. 52 00:03:30,600 --> 00:03:35,160 And then you come across resources like this and you read through them and you go okay there's some 53 00:03:35,160 --> 00:03:37,860 potential fixes this might be my issue. 54 00:03:37,860 --> 00:03:44,070 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 55 00:03:44,100 --> 00:03:48,900 I found a work around that you can do without having to downgrade Matt pot legal or wait for the update 56 00:03:48,900 --> 00:04:01,070 to come through and that's fix the broken annotations this happened in Fort Lee but three point one 57 00:04:01,070 --> 00:04:01,810 point one. 58 00:04:01,850 --> 00:04:04,440 By the time you try out this right. 59 00:04:04,460 --> 00:04:09,110 This function may work perfectly for you because you'd be using that pot lib three point one point to 60 00:04:09,380 --> 00:04:10,700 where the error gets fixed. 61 00:04:10,700 --> 00:04:13,070 But if not this is a workaround right. 62 00:04:13,080 --> 00:04:14,540 That's what we are as engineers. 63 00:04:14,540 --> 00:04:20,300 We're looking for solutions to our problems not necessarily work arounds but solutions to our problems. 64 00:04:20,330 --> 00:04:28,600 This is why Lim so this is going to say bottom top X equals get Y limitation so we're getting the limitations 65 00:04:28,600 --> 00:04:38,020 about y axis is here and then we're gonna go X dot set y lim gonna go bottom plus zero point five and 66 00:04:38,020 --> 00:04:40,790 then top minus zero point five. 67 00:04:41,810 --> 00:04:46,580 We can take out the semicolon here put it here so what is this doing. 68 00:04:46,680 --> 00:04:48,420 First of all let's see it. 69 00:04:48,540 --> 00:04:49,400 Wonderful. 70 00:04:49,410 --> 00:04:56,190 So this is just saying hey set bottom and top to the current Y limitations of our accesses and then 71 00:04:56,370 --> 00:05:04,640 reset them to b bottom plus O point five so it's gonna move that number up like a comment at this it's 72 00:05:04,650 --> 00:05:10,650 gonna move that number up and then it's going to bring this number down or these two numbers down. 73 00:05:10,710 --> 00:05:12,960 So that's all that's happening in these two lines. 74 00:05:13,080 --> 00:05:17,040 And that was a fix again I found through a little bit of searching searching up something like that 75 00:05:17,820 --> 00:05:21,540 seaborne heat map plot numbers not appearing in the right way. 76 00:05:21,660 --> 00:05:27,890 Now that's looking a bit more like what we used in our confusion matrix anatomy. 77 00:05:27,990 --> 00:05:28,930 Beautiful. 78 00:05:29,130 --> 00:05:32,100 And now that's looking like exactly something you can start to share. 79 00:05:32,100 --> 00:05:36,860 You could even start to try and customize these labels here so that someone knows what zero is. 80 00:05:36,930 --> 00:05:41,600 Or put a little key here so zero is not heart disease one is heart disease. 81 00:05:41,760 --> 00:05:46,020 You could customize this as much as you want but it's essentially one of the best ways to visualize 82 00:05:46,200 --> 00:05:47,540 a confusion matrix. 83 00:05:47,550 --> 00:05:53,660 Now you might be asking is why do we jump straight to Seabourn instead of using psychic line. 84 00:05:53,670 --> 00:05:55,910 Surely they have a plotting and confusion matrix. 85 00:05:55,920 --> 00:05:57,640 And I thought the same thing too. 86 00:05:57,780 --> 00:06:07,500 But if we look at this if we go from S.K. lone dot matrix import plot confusion matrix and we go plot 87 00:06:07,920 --> 00:06:17,720 confusion matrix pass it out CnF so if we look at is cannot import name plot confusion matrix from psychic 88 00:06:17,730 --> 00:06:19,280 line Why is that. 89 00:06:19,400 --> 00:06:20,360 So we're going here. 90 00:06:20,450 --> 00:06:32,580 So I can't learn plot confusion matrix confusion matrix okay and then we go down here houses happening. 91 00:06:32,690 --> 00:06:36,410 So from S.K. learned dot matrix import plot confusion matrix. 92 00:06:36,440 --> 00:06:37,100 Okay. 93 00:06:37,310 --> 00:06:43,120 We see that they've used the function here and now we click on this SDK lined up matrix plot confusion 94 00:06:43,120 --> 00:06:43,900 matrix. 95 00:06:44,060 --> 00:06:44,550 All right. 96 00:06:45,250 --> 00:06:46,360 So that's what we've done right. 97 00:06:46,600 --> 00:06:54,250 We've imported it from here from SDK lined up matrix import plot confusion matrix yet it still doesn't 98 00:06:54,250 --> 00:06:55,120 work. 99 00:06:55,150 --> 00:06:59,800 This is one of the caveats of using an open source library right is that although psychic line is incredibly 100 00:06:59,800 --> 00:07:04,180 helpful in offering us a bunch of different functions and same goes for any other open source library 101 00:07:04,540 --> 00:07:08,390 there are some cases where certain functions may not work right like this. 102 00:07:08,410 --> 00:07:09,490 We try to import it. 103 00:07:09,520 --> 00:07:10,270 It doesn't work. 104 00:07:10,420 --> 00:07:14,910 So again it's another example of where we've created a solution to our problem. 105 00:07:14,920 --> 00:07:20,700 If we couldn't use psychic loans metrics function plot confusion matrix we build our own. 106 00:07:20,800 --> 00:07:28,480 We use seaborne heat map or we could even just use Panda's cross tab as a prime example of putting on 107 00:07:28,480 --> 00:07:30,920 our engineering hat and figuring things out. 108 00:07:31,030 --> 00:07:35,950 But in essence the main thing to remember with the confusion matrix is it shows you where your model 109 00:07:35,950 --> 00:07:37,550 is getting confused. 110 00:07:37,600 --> 00:07:43,770 If we go back to our anatomy the correct predictions are going to be along the diagonal and the false 111 00:07:43,770 --> 00:07:48,180 negatives and false positives are going to be on either side of that diagonal. 112 00:07:48,180 --> 00:07:52,710 So with that being said we've covered a fair few things that the confusion matrix. 113 00:07:52,710 --> 00:07:58,950 Let's have a look at one final classification metric which is also really important and that is called 114 00:07:59,400 --> 00:08:02,300 the classification report. 115 00:08:02,540 --> 00:08:06,000 Changes in a marked down and we'll finish the video there. 116 00:08:06,020 --> 00:08:06,900 We'll see in the next one.