1 00:00:00,666 --> 00:00:01,033 Okay. 2 00:00:01,033 --> 00:00:02,900 So let's have a look at the arguments. 3 00:00:02,900 --> 00:00:04,666 The first argument is formula. 4 00:00:04,666 --> 00:00:08,400 So as for SVM it's going to be purchased tilde. 5 00:00:08,400 --> 00:00:09,700 And then a point. 6 00:00:09,700 --> 00:00:12,600 And the point represents all the independent variables. 7 00:00:12,600 --> 00:00:15,566 So we know this then data. Okay. 8 00:00:15,566 --> 00:00:19,600 So yes you need to specify the data because you want to specify the data 9 00:00:19,600 --> 00:00:22,933 set on which you want to train your kernel SVM model. 10 00:00:23,400 --> 00:00:25,800 So we need to specify data equals training set. 11 00:00:25,800 --> 00:00:28,566 Because we are training a model on the training set. 12 00:00:28,566 --> 00:00:31,500 Then x, y and scale are not important here. 13 00:00:31,500 --> 00:00:35,133 What's really important are the type and the kernel. 14 00:00:35,766 --> 00:00:38,933 So the type is whether you want to make a regression model 15 00:00:39,066 --> 00:00:43,566 that is SVM for regression, that is SVR that we saw in the regression part, 16 00:00:44,000 --> 00:00:48,566 or SVM for classification, which is the common way of saying SVM. 17 00:00:49,100 --> 00:00:52,600 So here we will need to specify the C classification type, 18 00:00:52,600 --> 00:00:56,400 which is the default type for classification for SVM. 19 00:00:56,700 --> 00:01:00,433 Remember in the as the R we chose EPS regression. 20 00:01:00,633 --> 00:01:03,933 That was the default type for regression for SVM. 21 00:01:04,366 --> 00:01:05,600 But here we are in classification. 22 00:01:05,600 --> 00:01:08,366 So we will choose this classification type. 23 00:01:08,366 --> 00:01:10,500 And then the most important is the kernel. 24 00:01:10,500 --> 00:01:12,266 Here we jumped to a higher level. 25 00:01:12,266 --> 00:01:15,800 We are making a more sophisticated SVM than the SVM we did 26 00:01:15,800 --> 00:01:19,600 in the previous section, which was a linear kernel SVM. 27 00:01:20,033 --> 00:01:24,600 But now we want to go pro and we are choosing a Gaussian SVM, 28 00:01:24,833 --> 00:01:25,833 which you will see 29 00:01:25,833 --> 00:01:29,800 make a terrific job at classifying your users in the social network. 30 00:01:30,000 --> 00:01:33,266 Because remember the kernel SVM was linear, 31 00:01:33,266 --> 00:01:36,300 which made our SVM model a linear classifier 32 00:01:36,600 --> 00:01:40,466 and therefore the separator separating the two classes of users 33 00:01:40,466 --> 00:01:44,500 was a straight line here and therefore couldn't get the users here. 34 00:01:44,500 --> 00:01:47,500 That made our data set non-linearly separable. 35 00:01:47,600 --> 00:01:50,200 So here we're going to choose the Gaussian kernel, 36 00:01:50,200 --> 00:01:53,033 which is going to be the radial basis kernel. 37 00:01:53,033 --> 00:01:54,966 Actually we're not going to write radial basis. 38 00:01:54,966 --> 00:01:57,466 We're just going to write radial. That's how it works. 39 00:01:57,466 --> 00:02:00,100 But the Gaussian kernel is radial. 40 00:02:00,100 --> 00:02:01,966 Actually you can see the formula here. 41 00:02:01,966 --> 00:02:04,466 Carol gave you the formula of the Gaussian kernel. 42 00:02:04,466 --> 00:02:05,900 And here it is. 43 00:02:05,900 --> 00:02:06,166 Okay. 44 00:02:06,166 --> 00:02:09,166 So now let's jump back to our code 45 00:02:09,533 --> 00:02:12,333 and let's implement this. 46 00:02:12,333 --> 00:02:12,600 Okay. 47 00:02:12,600 --> 00:02:15,566 So remember the first argument was formula. 48 00:02:16,666 --> 00:02:18,066 And then here we have to 49 00:02:18,066 --> 00:02:21,833 first take the dependent variable which is purchased. 50 00:02:22,500 --> 00:02:25,700 Now if we go back to our data set this is the dependent variable. 51 00:02:25,700 --> 00:02:29,666 And this is purchased then tilde which is alt n 52 00:02:30,333 --> 00:02:34,666 and then a dot to take all the independent variables of our training set. 53 00:02:35,300 --> 00:02:38,366 That is we're taking age and estimated salary. 54 00:02:40,000 --> 00:02:44,166 All right then comma to go to the next argument enter. 55 00:02:44,300 --> 00:02:46,200 And then the second argument. 56 00:02:46,200 --> 00:02:49,200 So the second argument remember it was data 57 00:02:49,466 --> 00:02:52,200 equals the training set okay. 58 00:02:52,200 --> 00:02:53,766 And then the next parameter what was it. 59 00:02:53,766 --> 00:02:55,900 It was type 60 00:02:55,900 --> 00:02:58,933 type equals C classification. 61 00:02:58,933 --> 00:03:01,500 Actually we don't really need to input the type here 62 00:03:01,500 --> 00:03:03,433 because it's the default type. 63 00:03:03,433 --> 00:03:06,766 But let's specify this to, you know, make the distinction between 64 00:03:07,066 --> 00:03:12,600 SVM for regression SVR and SVM for classification kernel SVM here. 65 00:03:13,333 --> 00:03:17,466 And then of course we will add the essential parameter 66 00:03:17,466 --> 00:03:20,466 for this section kernel SVM which is of course kernel. 67 00:03:20,766 --> 00:03:24,866 And that's where we pick our more sophisticated kernel 68 00:03:25,000 --> 00:03:29,033 which is the Gaussian kernel call here radial. 69 00:03:30,300 --> 00:03:31,000 All right. 70 00:03:31,000 --> 00:03:33,233 Now our classifier is ready. 71 00:03:33,233 --> 00:03:36,233 So let's immediately select this. 72 00:03:37,866 --> 00:03:40,800 And perfect our classifier is now built. 73 00:03:40,800 --> 00:03:43,833 So now let's use it to predict the test results. 74 00:03:44,133 --> 00:03:48,266 So we're going to select this line simply and press Command and control. 75 00:03:48,266 --> 00:03:49,933 Press enter to execute. 76 00:03:49,933 --> 00:03:52,433 And here is our Y prat. Let's have a look. 77 00:03:52,433 --> 00:03:53,666 Why pred. 78 00:03:53,666 --> 00:03:56,666 We type right pred here in the console press enter. 79 00:03:57,133 --> 00:04:00,666 And here we have all the predictions for the test set. 80 00:04:01,266 --> 00:04:02,566 So there are 100 predictions. 81 00:04:02,566 --> 00:04:04,600 So let's have a look at the first one. 82 00:04:04,600 --> 00:04:08,200 So we need to compare this widespread which is the vector of predictions 83 00:04:08,366 --> 00:04:11,366 with the true results of the observations, 84 00:04:11,400 --> 00:04:14,633 the true results, whether they bought yes or no, the SUV. 85 00:04:15,400 --> 00:04:18,300 And for this we need to go to the test and here to check it out. 86 00:04:18,300 --> 00:04:20,800 So let's see the one, two, three, 87 00:04:20,800 --> 00:04:23,866 four and five users didn't buy the SUV. 88 00:04:23,866 --> 00:04:25,133 In reality. 89 00:04:25,133 --> 00:04:30,633 And our predictor predicted that the same five users didn't buy the SUV. 90 00:04:30,766 --> 00:04:32,266 So that's some correct predictions. 91 00:04:32,266 --> 00:04:33,966 It's a very good start. 92 00:04:33,966 --> 00:04:37,633 Then if we look at the next observation we have one here, one here, 93 00:04:37,933 --> 00:04:39,200 one here, one here. 94 00:04:39,200 --> 00:04:42,233 So that makes the eight first predictions correct predictions. 95 00:04:42,233 --> 00:04:45,900 And here we have our first mistake, our first incorrect predictions. 96 00:04:45,900 --> 00:04:49,066 Because for the user number 22, 97 00:04:49,300 --> 00:04:52,966 our classifier predicts that this user wouldn't buy the SUV. 98 00:04:53,333 --> 00:04:55,466 And in reality it did. 99 00:04:55,466 --> 00:04:58,500 If we look at the number 22, we can see that we have a one here, 100 00:04:58,500 --> 00:05:01,500 which means that this user bought the SUV. 101 00:05:01,566 --> 00:05:03,866 Okay, so but the best way to look at these 102 00:05:03,866 --> 00:05:06,866 prediction is to use the confusion matrix. 103 00:05:06,900 --> 00:05:08,033 So let's do this. 104 00:05:08,033 --> 00:05:09,600 The section is here already. 105 00:05:09,600 --> 00:05:11,400 We don't have to change anything. 106 00:05:11,400 --> 00:05:14,400 The template is there to ease our work. 107 00:05:14,400 --> 00:05:16,500 So let's select this line. 108 00:05:16,500 --> 00:05:18,900 Let's give it a control. Press enter to execute. 109 00:05:18,900 --> 00:05:21,233 And here we have our matrix. 110 00:05:21,233 --> 00:05:24,233 So we're going to look at it in the console. 111 00:05:24,233 --> 00:05:26,233 So cmd here enter. 112 00:05:26,233 --> 00:05:28,700 And here is the matrix okay. 113 00:05:28,700 --> 00:05:30,166 So what do we have here. 114 00:05:30,166 --> 00:05:35,066 We have 58 plus 32 equals 90 correct predictions. 115 00:05:35,500 --> 00:05:39,300 And four plus six equals ten incorrect predictions. 116 00:05:40,000 --> 00:05:40,866 So that's not too bad.