1 00:00:00,033 --> 00:00:01,533 Okay, my friends, let's do this. 2 00:00:01,533 --> 00:00:05,233 Are you ready to implement the code to visualize your results? 3 00:00:05,400 --> 00:00:07,266 Here we go. Let's do it together. 4 00:00:07,266 --> 00:00:08,833 So we're going to do it efficiently. 5 00:00:08,833 --> 00:00:09,633 We're going to start from 6 00:00:09,633 --> 00:00:13,566 our polynomial regression implementation the visualization code at the end. 7 00:00:13,800 --> 00:00:15,300 So we're going to copy it. 8 00:00:15,300 --> 00:00:19,700 Then we're going to create a new code cell here and paste it. 9 00:00:19,966 --> 00:00:20,633 Okay. 10 00:00:20,633 --> 00:00:24,300 And now the exercise is to figure out what we have 11 00:00:24,300 --> 00:00:27,800 to change here in order to adapt to our SVR model. 12 00:00:28,066 --> 00:00:30,633 So let's do this. First let's make the obvious change. 13 00:00:30,633 --> 00:00:35,333 Let's replace here polynomial regression by SVR. 14 00:00:35,566 --> 00:00:38,800 And then let's see row by row what we have to change. 15 00:00:39,066 --> 00:00:39,400 Okay. 16 00:00:39,400 --> 00:00:42,633 So for the first row remember that x and y 17 00:00:42,633 --> 00:00:45,966 are the scaled values of the inputs and the outputs. 18 00:00:46,100 --> 00:00:49,500 So if we want to have a nice plot with the original values 19 00:00:49,500 --> 00:00:52,666 of the position levels and the salaries, well the first thing we have to do 20 00:00:52,666 --> 00:00:57,800 is to reverse the scale of the inputs x and y to put them in their original scale. 21 00:00:57,966 --> 00:00:58,600 Okay. 22 00:00:58,600 --> 00:01:01,500 And to do so well, we're going to take our scaler objects 23 00:01:01,500 --> 00:01:05,833 X, NSC, y and applied inverse transform method on each of them. 24 00:01:06,066 --> 00:01:08,466 Okay. So let's do this. Let's start with x. 25 00:01:08,466 --> 00:01:13,966 We take our c x scaler object from which we apply 26 00:01:13,966 --> 00:01:18,666 the inverse underscore transform method onto x. 27 00:01:18,833 --> 00:01:20,166 Okay. Perfect. 28 00:01:20,166 --> 00:01:21,400 Now these are the same for y. 29 00:01:21,400 --> 00:01:24,500 Let's take our c y scaler 30 00:01:24,500 --> 00:01:27,500 object from which we call again to inverse 31 00:01:27,900 --> 00:01:31,166 transform form method onto y. 32 00:01:31,733 --> 00:01:32,433 Excellent. 33 00:01:32,433 --> 00:01:34,466 And we're done with the first row. 34 00:01:34,466 --> 00:01:35,966 Now second row. 35 00:01:35,966 --> 00:01:39,433 Let's take care separately of the input x and the prediction. 36 00:01:39,600 --> 00:01:43,466 So for x once again we have to apply the reverse transformation 37 00:01:43,633 --> 00:01:44,833 to get the original square. 38 00:01:44,833 --> 00:01:49,766 So there we go again we call our c underscore x square object 39 00:01:50,066 --> 00:01:54,833 from which we apply again the inverse transform method. 40 00:01:54,833 --> 00:01:57,833 There we go. Apply to x. Okay. 41 00:01:58,233 --> 00:02:00,600 And now this is where things get interesting. 42 00:02:00,600 --> 00:02:04,200 We're going to take care of the predictions now of the inputs and x. 43 00:02:04,466 --> 00:02:07,433 So of course we have to remove this whole line rect to predict fully 44 00:02:07,433 --> 00:02:10,433 rect fit transform x and replace it by something. 45 00:02:10,466 --> 00:02:13,400 And now the question is what do we have to replace it with. 46 00:02:13,400 --> 00:02:18,166 Well it is going to be something similar to the prediction we made here. 47 00:02:18,300 --> 00:02:21,300 Only here we made it for a single observation. 48 00:02:21,300 --> 00:02:24,133 And so we need to adapt this to X. Right. 49 00:02:24,133 --> 00:02:27,133 Because now we're making the predictions of the inputs in the x. 50 00:02:27,266 --> 00:02:27,833 Okay. 51 00:02:27,833 --> 00:02:31,166 So what we're going to do is take this whole prediction here. 52 00:02:31,433 --> 00:02:32,233 We're going to replace 53 00:02:32,233 --> 00:02:36,900 that whole line rect to predict rect fit transform x by the prediction. 54 00:02:36,900 --> 00:02:37,966 We just copied. 55 00:02:37,966 --> 00:02:39,900 And now let's see how we have to adapt this. 56 00:02:39,900 --> 00:02:42,300 So let's start from inside the predict method. 57 00:02:42,300 --> 00:02:44,766 Of course we want to replace 6.5 by x. 58 00:02:44,766 --> 00:02:48,600 But here we had to apply x transform on 6.5. 59 00:02:48,600 --> 00:02:51,266 Because 6.5 is the original square. 60 00:02:51,266 --> 00:02:54,033 And the predict method has to be applied on the scaled values. 61 00:02:54,033 --> 00:02:59,133 But now since we apply the break method on x and since x is already scaled 62 00:02:59,300 --> 00:03:02,566 well, we must not reapply the transform method on x, 63 00:03:02,566 --> 00:03:07,800 and therefore what we need to replace here is this whole six transform 6.5 64 00:03:08,000 --> 00:03:11,566 by indeed x because x is already scaled. 65 00:03:11,633 --> 00:03:12,933 So there we go. 66 00:03:12,933 --> 00:03:15,000 And now I think that's it. I think we're done. 67 00:03:15,000 --> 00:03:16,033 That was pretty efficient. 68 00:03:16,033 --> 00:03:18,500 But you know we're never too safe from human error. 69 00:03:18,500 --> 00:03:22,633 So we're going to double check this by executing right away. 70 00:03:22,833 --> 00:03:23,866 Could see up here. 71 00:03:23,866 --> 00:03:24,666 So there we go. 72 00:03:24,666 --> 00:03:25,933 Let's click run cell here. 73 00:03:25,933 --> 00:03:28,933 And let's see what happens. And there we go. 74 00:03:28,966 --> 00:03:30,466 We did it all correctly. 75 00:03:30,466 --> 00:03:32,966 This is indeed the curve of the SVM model. 76 00:03:32,966 --> 00:03:38,000 And as we can see the predictions in blue go pretty close to real outcomes in 77 00:03:38,000 --> 00:03:41,066 red except for that last one which would make it an outlier. 78 00:03:41,066 --> 00:03:42,500 But that's how it is.