1 00:00:00,200 --> 00:00:01,866 Hello my friends, and welcome 2 00:00:01,866 --> 00:00:06,333 to this new practical activity on this time the kernel SVM model. 3 00:00:06,600 --> 00:00:09,866 So please follow me into part three classification 4 00:00:09,900 --> 00:00:13,100 to implement the kernel SVM model. 5 00:00:13,433 --> 00:00:15,533 And as usual we're going to start with Python. 6 00:00:15,533 --> 00:00:18,900 And here we are with our two files. 7 00:00:19,066 --> 00:00:20,400 The first one that contains 8 00:00:20,400 --> 00:00:24,600 the whole implementation of the kernel SVM model in the Ipynb format. 9 00:00:24,900 --> 00:00:29,066 And the second one the data set, that same data set on which we trained 10 00:00:29,066 --> 00:00:32,066 and will train all the classification models of this part. 11 00:00:32,233 --> 00:00:34,333 So let's have a quick look at it again. 12 00:00:34,333 --> 00:00:38,033 This data set contains some information of 400 customers 13 00:00:38,266 --> 00:00:40,300 represented by each row here. 14 00:00:40,300 --> 00:00:42,366 So each row corresponds to a customer. 15 00:00:42,366 --> 00:00:46,633 And for each of these customers, well we have the age which is a first feature. 16 00:00:46,800 --> 00:00:49,300 The estimated salary which is a second feature. 17 00:00:49,300 --> 00:00:53,000 And the dependent variable purchased which tells whether or not 18 00:00:53,166 --> 00:00:57,033 they bought no or yes, a previous SUV. 19 00:00:57,400 --> 00:00:57,900 All right. 20 00:00:57,900 --> 00:00:59,600 And so in our practical activities 21 00:00:59,600 --> 00:01:03,533 of this part three classification, we build several classification models 22 00:01:03,533 --> 00:01:06,766 to understand the correlations between these two features here. 23 00:01:06,966 --> 00:01:11,866 And this dependent variable purchased in order to predict which future customers 24 00:01:11,866 --> 00:01:16,566 will buy brand new luxury SUV that is advertised on social networks. 25 00:01:16,733 --> 00:01:19,600 All right. So still the same story. And now. 26 00:01:19,600 --> 00:01:23,333 Well, let's begin our kernel SVM implementation. 27 00:01:23,533 --> 00:01:25,800 I'm going to open it with Google Colaboratory. 28 00:01:25,800 --> 00:01:28,800 But you have the choice to open it with Jupyter Notebook as well. 29 00:01:28,833 --> 00:01:30,033 Choose your favorite. 30 00:01:30,033 --> 00:01:33,966 And now it is opening the notebook loading it, laying it out. 31 00:01:33,966 --> 00:01:35,533 And there we go. 32 00:01:35,533 --> 00:01:38,800 Welcome to the kernel SVM implementation. 33 00:01:39,500 --> 00:01:39,900 All right. 34 00:01:39,900 --> 00:01:43,500 And of course it results from the exact same classification template 35 00:01:43,500 --> 00:01:46,666 which we made in the first section of this part logistic regression. 36 00:01:46,966 --> 00:01:49,733 Indeed, when we built the logistic regression model, 37 00:01:49,733 --> 00:01:53,300 we made at the same time a great classification template 38 00:01:53,500 --> 00:01:58,733 which allows us to only change one cell when building another classification 39 00:01:58,900 --> 00:02:02,733 model, which is exactly, you know, the cell where we build 40 00:02:02,733 --> 00:02:05,733 and train this classification model on the training set. 41 00:02:05,733 --> 00:02:08,933 So this cell is the only one we have to modify here. 42 00:02:09,066 --> 00:02:12,466 However, this notebook is in read only mode. 43 00:02:12,566 --> 00:02:15,600 So in order to modify this cell to build a kernel SVM model, 44 00:02:15,800 --> 00:02:21,033 we have to indeed click file here in order to create a copy of this notebook. 45 00:02:21,233 --> 00:02:24,233 And to do this you just need to click save a Copy and drive. 46 00:02:24,466 --> 00:02:27,200 This will create a copy of this notebook. 47 00:02:27,200 --> 00:02:31,800 And in a second you'll have it opened on your machine. 48 00:02:32,100 --> 00:02:34,666 All right so I'm going to put everything in that order. 49 00:02:34,666 --> 00:02:35,400 All right. 50 00:02:35,400 --> 00:02:36,733 And now this is our copy. 51 00:02:36,733 --> 00:02:40,866 And so inside the only thing we have to re-implement is indeed that cell 52 00:02:40,866 --> 00:02:44,600 where we build and train the kernel SVM model on the training set. 53 00:02:44,933 --> 00:02:47,100 So let's not look at it. 54 00:02:47,100 --> 00:02:48,766 Let's put it in the trash. 55 00:02:48,766 --> 00:02:52,066 And now let's re-implement it from scratch. 56 00:02:52,733 --> 00:02:53,666 All right. Perfect. 57 00:02:53,666 --> 00:02:56,766 So it's actually super, super easy. 58 00:02:57,133 --> 00:03:01,400 We can even do it even more efficiently than, you know, the usual way. 59 00:03:01,400 --> 00:03:06,033 When we went to the cycling API, then got the name of the function 60 00:03:06,366 --> 00:03:10,200 because, as I explained in the previous section, when building the SVM model, 61 00:03:10,200 --> 00:03:15,066 the classic one, well, the way we built it was actually to, you know, build 62 00:03:15,066 --> 00:03:18,800 an object of this class as VC and then choose a linear kernel. 63 00:03:19,133 --> 00:03:21,433 And now actually, you know, we're about to do the same. 64 00:03:21,433 --> 00:03:25,133 We're about to use the same class to build this kernel, SVM objects. 65 00:03:25,266 --> 00:03:27,933 But this time, instead of choosing a linear kernel, 66 00:03:27,933 --> 00:03:29,733 we will choose a nonlinear one. 67 00:03:29,733 --> 00:03:31,333 And that's the best example of it. 68 00:03:31,333 --> 00:03:36,533 You know, the most commonly used it is the RBF radial basis function kernel. 69 00:03:37,133 --> 00:03:41,133 And you also have some other ones like the polynomial kernel or the sigmoid kernel. 70 00:03:41,266 --> 00:03:44,100 But really this one is the best option to start with. 71 00:03:44,100 --> 00:03:48,233 And that's the one we'll choose for our kernel SVM implementation, 72 00:03:48,266 --> 00:03:49,500 as you might have guessed. 73 00:03:49,500 --> 00:03:52,266 And therefore remember how I also want to train you on 74 00:03:52,266 --> 00:03:55,866 how to juggle with the different tools of your machine learning toolkit. 75 00:03:55,866 --> 00:03:59,200 You know, the data preprocessing toolkit or the regression toolkit, or even now 76 00:03:59,200 --> 00:04:02,200 the classification toolkit containing all your classification models. 77 00:04:02,500 --> 00:04:08,366 The most efficient way now to build this kernel SVM model is just to go back 78 00:04:08,366 --> 00:04:13,933 to our SVM implementation, then find that cell where we built the SVM. 79 00:04:14,100 --> 00:04:18,600 And indeed, since we built that SVM with the same class as VC, 80 00:04:18,800 --> 00:04:22,733 but choosing a linear kernel, well now as simple as that. 81 00:04:22,733 --> 00:04:26,900 In order to build a kernel SVM, we just need to take this code cell 82 00:04:27,166 --> 00:04:30,566 and paste it right here in a new code cell. 83 00:04:30,733 --> 00:04:31,833 And then guess what? 84 00:04:31,833 --> 00:04:34,833 Just change that kernel parameter. 85 00:04:35,033 --> 00:04:35,733 All right. 86 00:04:35,733 --> 00:04:38,933 And as we said this time we're not using a linear kernel. 87 00:04:38,933 --> 00:04:41,400 We're going to use an RBF kernel. 88 00:04:41,400 --> 00:04:45,133 The radial basis function which was explained in the intuition lectures. 89 00:04:45,433 --> 00:04:47,000 And there you go, my friend. 90 00:04:47,000 --> 00:04:49,433 That implementation is over. 91 00:04:49,433 --> 00:04:50,733 You see how I'm doing 92 00:04:50,733 --> 00:04:54,433 all these templates to make you as most efficient as possible? 93 00:04:54,566 --> 00:04:55,600 Well, that's what I mean. 94 00:04:55,600 --> 00:04:58,700 Now we can juggle between our different codes, different tools 95 00:04:58,700 --> 00:05:02,400 of machine learning, and we can build new models in flashlight. 96 00:05:02,633 --> 00:05:05,633 And that's what we just did with kernel SVM. 97 00:05:05,800 --> 00:05:08,100 All right. So basically we're done. We're ready. 98 00:05:08,100 --> 00:05:12,433 So the next natural step is to upload the data set inside the notebook. 99 00:05:12,733 --> 00:05:15,633 And to do this you need to click this folder button here. 100 00:05:15,633 --> 00:05:20,200 Then your notebook will be connecting to a runtime to enable file browsing. 101 00:05:20,266 --> 00:05:21,400 Still the same story. 102 00:05:21,400 --> 00:05:25,100 In a few seconds we should be able to see the upload button. 103 00:05:25,133 --> 00:05:26,766 Perfect. There we go. 104 00:05:26,766 --> 00:05:28,500 And so now we're going to click it 105 00:05:28,500 --> 00:05:31,200 and we will directly get access to social network. 106 00:05:31,200 --> 00:05:34,200 As if you know you were here in the SVM section. 107 00:05:34,366 --> 00:05:36,533 But let me show you the path once again. 108 00:05:36,533 --> 00:05:39,900 So please find first your whole machine learning is that folder. 109 00:05:40,033 --> 00:05:44,000 Then please go to part three, then section 17 kernel SVM, 110 00:05:44,200 --> 00:05:48,333 then Python and then social network ads dot CSV. 111 00:05:48,733 --> 00:05:49,300 Perfect. 112 00:05:49,300 --> 00:05:52,300 It will upload as a data set inside the notebook. 113 00:05:52,533 --> 00:05:53,333 And now. 114 00:05:53,333 --> 00:05:58,100 Now we can run everything by clicking runtime here and then run