1 00:00:00,300 --> 00:00:02,400 But now the most exciting part is coming 2 00:00:02,400 --> 00:00:05,400 because we're going to be visualizing the training set results. 3 00:00:06,200 --> 00:00:06,900 And actually, right now 4 00:00:06,900 --> 00:00:10,800 we don't have to change anything except maybe the title here classifier. 5 00:00:11,300 --> 00:00:13,966 And then here you need to specify kernel 6 00:00:13,966 --> 00:00:18,066 SVM, kernel SVM as well as here in the test set. 7 00:00:18,066 --> 00:00:21,166 So here kernel SVM as well. 8 00:00:22,966 --> 00:00:23,366 All right. 9 00:00:23,366 --> 00:00:27,733 Now we can get some coffee and just execute this and watch the results. 10 00:00:28,066 --> 00:00:30,000 So we're going to do this. 11 00:00:30,000 --> 00:00:32,966 We're going to first look at the results 12 00:00:32,966 --> 00:00:35,133 here and press Command and control. 13 00:00:35,133 --> 00:00:38,133 Press enter to execute. 14 00:00:40,666 --> 00:00:44,000 And wow these are the beautiful results of kernel SVM. 15 00:00:44,533 --> 00:00:47,400 We can see how it's making this curve here to classify. 16 00:00:47,400 --> 00:00:50,600 Well most of the users in the social network here are since 17 00:00:50,600 --> 00:00:53,600 we have a two dimensional space here for the data set, 18 00:00:53,600 --> 00:00:57,533 that means that the data set was mapped to a three dimensional space, 19 00:00:58,000 --> 00:00:59,800 and then on this dimensional space, 20 00:00:59,800 --> 00:01:02,700 it managed to make the data linearly separable, 21 00:01:02,700 --> 00:01:07,333 so that it can find a linear hyperplane that separates in a much better way. 22 00:01:07,333 --> 00:01:08,766 The two classes. 23 00:01:08,766 --> 00:01:12,533 And then it projected back to this two dimensional space 24 00:01:12,733 --> 00:01:18,066 to finally obtain this curve here that separates in a much better way 25 00:01:18,066 --> 00:01:21,900 the two classes than the linear classifier you would do with a straight line here, 26 00:01:22,100 --> 00:01:26,133 as we saw for logistic regression or SVM, SVM with the linear kernel. 27 00:01:26,566 --> 00:01:27,833 So that's what happened. 28 00:01:27,833 --> 00:01:29,700 That's what happened behind the scenes. 29 00:01:29,700 --> 00:01:31,500 The kernel SVM did an amazing job. 30 00:01:31,500 --> 00:01:33,266 So we can say congrats. 31 00:01:33,266 --> 00:01:36,533 Okay, so for those of you who are seeing this for the first time, 32 00:01:36,733 --> 00:01:38,566 I'll just quickly remind what it is. 33 00:01:38,566 --> 00:01:41,300 The points here are the true observations, the true results. 34 00:01:41,300 --> 00:01:45,300 So the red points are the users who didn't buy the SUV in reality, 35 00:01:45,533 --> 00:01:48,566 and the green points are the users who bought the SUV. 36 00:01:48,800 --> 00:01:51,766 And then the regions that we see here are the prediction regions. 37 00:01:51,766 --> 00:01:54,833 So the red region is the region where our model predicts 38 00:01:54,833 --> 00:01:58,133 that the user doesn't buy the SUV and the green region is the one 39 00:01:58,133 --> 00:02:01,133 where our model predicts that the user buys the SUV. 40 00:02:01,166 --> 00:02:05,033 So for example, that means that for this particular user red points, 41 00:02:05,266 --> 00:02:08,733 which is in the green region, that makes an incorrect prediction 42 00:02:08,733 --> 00:02:12,133 because the truth is, the user didn't buy the SUV. 43 00:02:12,466 --> 00:02:15,200 But since this user is in the green region, that means 44 00:02:15,200 --> 00:02:18,500 that the model predicted that this user bought the SUV, 45 00:02:18,733 --> 00:02:20,800 even if that's not what happened in real life. 46 00:02:20,800 --> 00:02:22,800 So that's where the graph is about. 47 00:02:22,800 --> 00:02:27,600 And here is the nonlinear separator of the kernel SVM algorithm. 48 00:02:27,900 --> 00:02:32,900 And thanks to this nonlinear separator our kernel SVM could classify correctly 49 00:02:32,900 --> 00:02:36,000 those users here, which wasn't the case for the linear 50 00:02:36,000 --> 00:02:38,300 separators because since we had the straight lines, 51 00:02:38,300 --> 00:02:41,433 it couldn't catch these users in the right category. 52 00:02:41,433 --> 00:02:43,666 That is the green category, because those users 53 00:02:43,666 --> 00:02:45,566 actually bought the SUV in real life. 54 00:02:45,566 --> 00:02:47,166 So they should be in the green region. 55 00:02:47,166 --> 00:02:49,400 And this wasn't the case for the linear separator. 56 00:02:49,400 --> 00:02:50,200 And now it's the case 57 00:02:50,200 --> 00:02:53,800 for the kernel SVM separator because it's a nonlinear classifier. 58 00:02:54,500 --> 00:02:55,000 Perfect. 59 00:02:55,000 --> 00:02:59,533 Now let's have a look at the test results to see how our model behaves 60 00:02:59,533 --> 00:03:02,366 on new observations, to see if it can still classify 61 00:03:02,366 --> 00:03:05,166 and predict the results of new observations. 62 00:03:05,166 --> 00:03:07,166 So we're going to do this. We only have to 63 00:03:08,700 --> 00:03:09,566 select this. 64 00:03:09,566 --> 00:03:10,533 Press command and control. 65 00:03:10,533 --> 00:03:13,533 Press enter to execute. 66 00:03:13,933 --> 00:03:16,433 And here are the test set results okay. 67 00:03:16,433 --> 00:03:18,200 So that looks great as well. 68 00:03:18,200 --> 00:03:21,600 First an important thing to understand is that the regions that we see 69 00:03:21,600 --> 00:03:24,600 here are the same regions as we saw in the data set. 70 00:03:24,700 --> 00:03:27,633 If you go back to the training set and then go back to the test set, 71 00:03:27,633 --> 00:03:31,933 you can see that the regions here don't change, only the observation 72 00:03:31,933 --> 00:03:34,933 points change because of course these are new observation points. 73 00:03:35,100 --> 00:03:36,900 And so here we can see that 74 00:03:36,900 --> 00:03:40,933 the kernel SVM did an amazing job at classifying new observations 75 00:03:40,933 --> 00:03:45,933 because all these test set observations here are the users who didn't buy the SUV, 76 00:03:45,933 --> 00:03:48,933 because the points are red and they are in the red region. 77 00:03:48,933 --> 00:03:52,500 That is the region where our classifier predicts that the users don't buy the SUV. 78 00:03:52,800 --> 00:03:54,633 So that's correct. Predictions. 79 00:03:54,633 --> 00:03:55,900 Same for these guys here. 80 00:03:55,900 --> 00:03:58,966 All the green points that fall in the green region. 81 00:03:59,333 --> 00:04:02,333 And of course we have those incorrect predictions 82 00:04:02,433 --> 00:04:05,000 which are for example, this green user here 83 00:04:05,000 --> 00:04:08,400 who is in the red region as well as those two green here. 84 00:04:08,400 --> 00:04:09,533 So that's three. 85 00:04:09,533 --> 00:04:12,000 Then we have the red users. This one, this one. 86 00:04:12,000 --> 00:04:17,166 So 456789 and actually ten. 87 00:04:17,200 --> 00:04:21,100 We can see that there is a little green point here hiding behind the red points 88 00:04:22,033 --> 00:04:22,466 okay. Yeah. 89 00:04:22,466 --> 00:04:24,233 So that's definitely a very good job. 90 00:04:24,233 --> 00:04:26,133 You will see how the next classifiers 91 00:04:26,133 --> 00:04:29,700 will make a different style of classification of separation. 92 00:04:30,133 --> 00:04:31,800 You will see that it won't be a curve. 93 00:04:31,800 --> 00:04:32,833 It will be something else. 94 00:04:32,833 --> 00:04:35,766 And I will let you find out about the surprise. 95 00:04:35,766 --> 00:04:38,933 But definitely the kernel SVM is a great classifier 96 00:04:38,933 --> 00:04:41,366 when your data is not linearly separable. 97 00:04:41,366 --> 00:04:45,033 And we can see how it definitely improved the results of the linear classifiers 98 00:04:45,033 --> 00:04:48,033 that we saw with logistic regression and SVM. 99 00:04:48,066 --> 00:04:48,466 All right. 100 00:04:48,466 --> 00:04:51,733 So thank you for watching this tutorial about kernel SVM. 101 00:04:51,900 --> 00:04:53,033 I hope you enjoyed it. 102 00:04:53,033 --> 00:04:56,400 There will be a few more surprises with the next classifiers, as I told you. 103 00:04:56,533 --> 00:04:58,200 Until then, enjoy machine learning.