1 00:00:00,133 --> 00:00:02,433 Hello and welcome to this art tutorial. 2 00:00:02,433 --> 00:00:05,933 So today we are going to implement our second nonlinear regression model. 3 00:00:06,000 --> 00:00:09,233 It's going to be the SVR support vector for regression. 4 00:00:09,533 --> 00:00:10,433 So let's do it. 5 00:00:10,433 --> 00:00:12,366 We're going to use a regression template. 6 00:00:12,366 --> 00:00:15,366 And you're going to see how it's going to be so easy. 7 00:00:15,566 --> 00:00:17,100 So let's start by doing the basics. 8 00:00:17,100 --> 00:00:18,966 Set the right folder as working directory. 9 00:00:18,966 --> 00:00:21,966 So we'll go to Machine learning A-Z part two regression. 10 00:00:22,366 --> 00:00:25,400 And then support vector regression right. 11 00:00:25,433 --> 00:00:26,466 That's the right folder. 12 00:00:26,466 --> 00:00:27,400 All good. 13 00:00:27,400 --> 00:00:31,600 Let's click on set as working directory to set the folder as a working directory. 14 00:00:32,066 --> 00:00:34,000 Great. And now we can start. 15 00:00:34,000 --> 00:00:36,366 So we're going to take our regression templates. 16 00:00:36,366 --> 00:00:39,933 And we're going to take everything from here to here. 17 00:00:40,500 --> 00:00:43,666 Copy and paste it in our SVR model. 18 00:00:44,266 --> 00:00:45,066 Here we go. 19 00:00:45,066 --> 00:00:47,133 And now we just need to change a few things. 20 00:00:47,133 --> 00:00:50,133 So let's start by changing the basics. 21 00:00:50,266 --> 00:00:53,266 We're going to replace regression model here by SVR. 22 00:00:53,766 --> 00:00:54,200 Okay. 23 00:00:55,166 --> 00:00:59,400 And same here SVR results. 24 00:01:00,100 --> 00:01:02,900 Okay. And same here. 25 00:01:02,900 --> 00:01:04,233 All right. 26 00:01:04,233 --> 00:01:05,466 That was the easy step. 27 00:01:05,466 --> 00:01:07,800 And now let's get to the interesting step. 28 00:01:07,800 --> 00:01:11,633 So this interesting step is of course to create our SVR regressor. 29 00:01:11,900 --> 00:01:13,333 And we are creating it here. 30 00:01:13,333 --> 00:01:15,433 So I'm going to remove this. 31 00:01:15,433 --> 00:01:18,100 And now let's create this regressor. 32 00:01:18,100 --> 00:01:20,433 It's going to take 3 or 4 lines as usual. 33 00:01:20,433 --> 00:01:21,466 It's going to be very simple. 34 00:01:21,466 --> 00:01:25,200 We're going to use a function which is the SVM function, 35 00:01:25,200 --> 00:01:29,400 very simply because the SVR you know is a support vector machine algorithm. 36 00:01:29,700 --> 00:01:32,700 But for regression, that's why we call it SVR. 37 00:01:32,700 --> 00:01:35,700 And therefore we're just taking it from the SVM function. 38 00:01:35,700 --> 00:01:38,400 And you will understand why perfectly. 39 00:01:38,400 --> 00:01:42,600 So first let's import the required package because this function 40 00:01:42,600 --> 00:01:46,133 is contained in a package which is the E10 71 package. 41 00:01:46,166 --> 00:01:50,400 So let's go to our package is here and let's check if we have it. 42 00:01:51,266 --> 00:01:54,833 So I have it because of course I used it before, but you might not have it. 43 00:01:54,833 --> 00:01:59,100 So in case you don't have it, I'm going to type this line here 44 00:01:59,266 --> 00:02:03,300 that you will need to execute to install this package. 45 00:02:03,566 --> 00:02:06,133 So you type install that package is here. 46 00:02:06,133 --> 00:02:09,166 And then in the parenthesis and in the quotes you type 47 00:02:09,166 --> 00:02:12,533 the name of the package which is E10 71. 48 00:02:13,066 --> 00:02:13,500 All right. 49 00:02:13,500 --> 00:02:16,500 And then you just select this line and execute. 50 00:02:16,666 --> 00:02:18,266 And this will install the package. 51 00:02:18,266 --> 00:02:20,900 I'm not going to do it because mine is already installed. 52 00:02:20,900 --> 00:02:23,900 And therefore I'm going to put that in comment. 53 00:02:23,933 --> 00:02:26,766 Just press command plus shift plus C. 54 00:02:26,766 --> 00:02:27,666 All right. 55 00:02:27,666 --> 00:02:31,333 And now let's actually also add this line library. 56 00:02:32,333 --> 00:02:36,066 And in parenthesis E10 71 not in quotes. 57 00:02:36,900 --> 00:02:40,233 And this will select automatically the package here 58 00:02:40,466 --> 00:02:43,966 E10 71 because this will not always be selected. 59 00:02:44,266 --> 00:02:46,966 But by including that in your script you will be all fine. 60 00:02:46,966 --> 00:02:49,433 This will always be selected. Okay. 61 00:02:49,433 --> 00:02:53,100 And now let's start creating our SVR regressor. 62 00:02:53,400 --> 00:02:56,733 So as usual we're going to start by defining our regressor 63 00:02:57,600 --> 00:03:00,600 regressor and then equals. 64 00:03:00,733 --> 00:03:03,866 And then as I mentioned before we're going to use the SVM function 65 00:03:04,100 --> 00:03:06,300 which is actually this. 66 00:03:06,300 --> 00:03:07,266 And then in parentheses. 67 00:03:07,266 --> 00:03:09,466 And now let's press here 68 00:03:09,466 --> 00:03:13,466 F1 to have a look at the arguments and see what we need to input. 69 00:03:14,066 --> 00:03:16,100 So the first argument is formula. 70 00:03:16,100 --> 00:03:18,033 So you start to know perfectly what it is. 71 00:03:18,033 --> 00:03:21,033 Of course the formula is 72 00:03:21,733 --> 00:03:23,333 our dependent variable 73 00:03:23,333 --> 00:03:26,100 which is remember salary 74 00:03:26,100 --> 00:03:30,600 and then tilde I just press alt n and then a dot here. 75 00:03:30,600 --> 00:03:34,066 And the dot specifies that we are taking all the independent variable 76 00:03:34,400 --> 00:03:35,633 of our data set. 77 00:03:36,766 --> 00:03:37,500 We actually have 78 00:03:37,500 --> 00:03:40,533 one independent variable which is the level independent variable. 79 00:03:40,566 --> 00:03:42,600 So we could also type here level. 80 00:03:42,600 --> 00:03:44,966 But most of the time we use the dot because of course 81 00:03:44,966 --> 00:03:47,966 we have a lot more than one independent variable. 82 00:03:48,266 --> 00:03:50,933 But as a reminder, I'm taking one independent variable here 83 00:03:50,933 --> 00:03:53,933 so that we can clearly see the visual graphic results 84 00:03:54,166 --> 00:03:57,166 of the different nonlinear models that we are building. 85 00:03:57,466 --> 00:04:00,333 Okay. So now let's add the second argument. 86 00:04:00,333 --> 00:04:01,800 So I'm adding a comma here. 87 00:04:01,800 --> 00:04:03,533 And then next argument. 88 00:04:03,533 --> 00:04:06,533 So the next argument is data okay 89 00:04:07,000 --> 00:04:10,000 I guess you know what this data argument will be. 90 00:04:10,500 --> 00:04:14,900 It's going to be of course our data set data set here 91 00:04:14,900 --> 00:04:18,300 because we did not create any training set or test set. 92 00:04:18,700 --> 00:04:20,900 You know before we used the training set. 93 00:04:20,900 --> 00:04:23,433 Here is the data. But here we don't have any training set. 94 00:04:23,433 --> 00:04:26,200 So of course we're going to take the whole data set 95 00:04:26,200 --> 00:04:29,200 because we want to make very accurate predictions okay. 96 00:04:29,400 --> 00:04:32,100 And now finally most important argument. 97 00:04:32,100 --> 00:04:33,866 Well all the arguments are important. 98 00:04:33,866 --> 00:04:37,400 But the most relevant for this section about SVR 99 00:04:37,566 --> 00:04:40,433 is actually the next arguments we are about to input. 100 00:04:40,433 --> 00:04:43,400 So this argument is actually not x or y. 101 00:04:43,400 --> 00:04:45,400 These are optional arguments. 102 00:04:45,400 --> 00:04:49,900 The most important argument I was just talking about is this one 103 00:04:49,900 --> 00:04:53,966 the type, because this argument type will actually specify 104 00:04:53,966 --> 00:04:57,900 if you're making an SVM model, which is used for classification, 105 00:04:58,233 --> 00:05:01,533 or an SVR model which is used for regression. 106 00:05:01,900 --> 00:05:04,933 So here, since we're building a non-linearity regression model, 107 00:05:05,100 --> 00:05:08,266 we will choose the EPS regression type. 108 00:05:08,933 --> 00:05:11,733 We could choose actually EPS regression or new regression. 109 00:05:11,733 --> 00:05:13,700 But as you can see we want to take the most common one. 110 00:05:13,700 --> 00:05:15,266 The EPS regression. 111 00:05:15,266 --> 00:05:18,100 And if we were making a SVM model 112 00:05:18,100 --> 00:05:21,933 for classification then we would have chosen C classification here. 113 00:05:21,933 --> 00:05:25,966 As you can see, association is the default type for classification. 114 00:05:26,466 --> 00:05:31,566 So in short if you want to do regression you choose type equals EPS regression. 115 00:05:31,966 --> 00:05:35,766 And if you want to do classification then you choose type equals C classification. 116 00:05:35,766 --> 00:05:40,100 And actually in the next part about classification we will make an SVM model. 117 00:05:40,133 --> 00:05:43,800 And for this specific model we will choose the classification type 118 00:05:44,800 --> 00:05:45,166 okay. 119 00:05:45,166 --> 00:05:46,500 But here we are doing regression. 120 00:05:46,500 --> 00:05:48,500 So we choose the EPS regression type. 121 00:05:48,500 --> 00:05:51,500 So let's input it I'm going to type here type 122 00:05:51,933 --> 00:05:55,400 equals eps regression. 123 00:05:55,966 --> 00:05:56,366 All right. 124 00:05:56,366 --> 00:05:59,366 And you need to put that in.