1 00:00:00,066 --> 00:00:01,033 So let's do this. 2 00:00:01,033 --> 00:00:03,900 Let's close the linear regression results. 3 00:00:03,900 --> 00:00:07,566 And let's start to visualize the polynomial regression results. 4 00:00:07,933 --> 00:00:11,933 And you're going to see now how easy it is to go from the linear 5 00:00:11,933 --> 00:00:14,933 regression results to the polynomial regression results. 6 00:00:14,933 --> 00:00:17,733 Because what we will simply do here is, 7 00:00:17,733 --> 00:00:21,600 you know, select this and paste it here. 8 00:00:21,966 --> 00:00:25,100 And now you will see how we only need to change very few things. 9 00:00:25,433 --> 00:00:27,400 So as usual let's start with the simplest. 10 00:00:27,400 --> 00:00:30,900 Let's replace linear here by polynomial 11 00:00:32,766 --> 00:00:33,500 okay. 12 00:00:33,500 --> 00:00:34,866 And now what do we need to change. 13 00:00:34,866 --> 00:00:35,200 Okay. 14 00:00:35,200 --> 00:00:38,366 So do we need to change something in the June point function. 15 00:00:38,400 --> 00:00:42,100 No of course because we want to keep the same real observations. 16 00:00:42,266 --> 00:00:43,600 So that's okay. 17 00:00:43,600 --> 00:00:46,600 And then do we need to change something in the germline function. 18 00:00:46,800 --> 00:00:48,066 Of course. Yes. 19 00:00:48,066 --> 00:00:51,833 Because here we are predicting the salaries of our 20 00:00:51,833 --> 00:00:55,700 ten levels in our data set according to our linear regression model. 21 00:00:56,100 --> 00:00:58,600 So according to you what do we need to change here. 22 00:00:58,600 --> 00:00:59,533 Very simply. 23 00:00:59,533 --> 00:01:03,700 Well actually we just need to change the regressor in the predict function. 24 00:01:04,066 --> 00:01:07,533 And instead of taking the line drag, which is the linear regressor, 25 00:01:07,800 --> 00:01:12,233 we're going to take the polynomial regressor that we called poly rank. 26 00:01:12,600 --> 00:01:13,566 And that's it. 27 00:01:13,566 --> 00:01:16,300 That's actually all we need to do to visualize 28 00:01:16,300 --> 00:01:18,000 the polynomial regression results. 29 00:01:18,000 --> 00:01:21,200 And you will see that in the next sections it will actually be the same. 30 00:01:21,200 --> 00:01:24,333 We will only need to change the regressor to plot 31 00:01:24,333 --> 00:01:27,933 the new graphic results of our future regressors. 32 00:01:28,433 --> 00:01:29,733 So that's very nice. 33 00:01:29,733 --> 00:01:33,000 We're actually ready right now to visualize the polynomial results. 34 00:01:33,200 --> 00:01:35,066 So let's do this with our waiting. 35 00:01:35,066 --> 00:01:39,133 I'm going to select this and press Command and Control. 36 00:01:39,133 --> 00:01:40,266 Press enter to execute. 37 00:01:42,033 --> 00:01:43,200 And here it is. 38 00:01:43,200 --> 00:01:46,433 As you can see this is not a straight line anymore. 39 00:01:46,833 --> 00:01:49,500 Let's zoom on the graph. 40 00:01:49,500 --> 00:01:50,000 All right. 41 00:01:50,000 --> 00:01:53,366 So as I just mentioned, the first reflex to have as a machine learning 42 00:01:53,366 --> 00:01:57,466 scientists is that, this is not a linear model anymore. 43 00:01:57,466 --> 00:01:59,400 And by the way, congratulations. 44 00:01:59,400 --> 00:02:02,700 You just made your very first non-linear model. 45 00:02:03,333 --> 00:02:06,533 We're going to see plenty of other non-linear models in this course. 46 00:02:06,766 --> 00:02:08,166 But this is your first one. 47 00:02:08,166 --> 00:02:09,933 So congratulations. 48 00:02:09,933 --> 00:02:12,266 So as you can see it's not a straight line. 49 00:02:12,266 --> 00:02:13,433 Now it's a curve. 50 00:02:13,433 --> 00:02:18,833 And we can immediately see that the curve is approaching much better. 51 00:02:18,833 --> 00:02:21,166 All the red observation points. 52 00:02:21,166 --> 00:02:24,433 And especially for the CEO here, the CEO wouldn't get mad 53 00:02:24,433 --> 00:02:28,333 now if we negotiated with him its future salary in a new company, 54 00:02:28,566 --> 00:02:32,166 because now the prediction is much closer to the realization point. 55 00:02:32,666 --> 00:02:38,700 And let's check our employee that is about to be hired and that has a 6.5 level. 56 00:02:39,100 --> 00:02:42,100 Well, 6.5 is around here. 57 00:02:42,166 --> 00:02:45,566 And when we project 6.5 on our polynomial regression 58 00:02:45,566 --> 00:02:50,900 model represented by this blue curve, here we get a predicted salary. 59 00:02:50,900 --> 00:02:55,466 Here I'm projecting the point on the curve back again on the salary axis. 60 00:02:55,666 --> 00:02:59,400 And we get actually a salary that is coming much closer 61 00:02:59,400 --> 00:03:04,833 to the salary mentioned by this future employee, which is around 160 K here. 62 00:03:04,833 --> 00:03:07,233 Well, we don't get the accurate prediction yet 63 00:03:07,233 --> 00:03:09,866 because that's what we were going to do in the next tutorial. 64 00:03:09,866 --> 00:03:13,533 But definitely this model is fitting much better. 65 00:03:13,566 --> 00:03:14,433 The data set. 66 00:03:14,433 --> 00:03:15,433 And now, just for fun, 67 00:03:15,433 --> 00:03:19,266 let's add a new degree to see how this model can still be much improved 68 00:03:19,266 --> 00:03:24,166 and almost passing by all the points very accurately as we add more degrees. 69 00:03:24,500 --> 00:03:25,300 So let's check it out. 70 00:03:25,300 --> 00:03:28,033 Let's close this and let's add a new degree. 71 00:03:28,033 --> 00:03:30,300 So very simply what we're going to do 72 00:03:30,300 --> 00:03:34,066 is add a new degree here by copying this line. 73 00:03:35,166 --> 00:03:36,400 Paste it here. 74 00:03:36,400 --> 00:03:40,666 And we're going to add a new column in our data set level four that will 75 00:03:40,666 --> 00:03:44,866 correspond to our original independent variable level at the power four. 76 00:03:45,233 --> 00:03:48,666 And so therefore here we need to compute it this way 77 00:03:48,666 --> 00:03:52,233 by taking the fourth power of level there. 78 00:03:52,700 --> 00:03:58,600 And now let's execute this line to add the level four column in our data set. 79 00:03:58,633 --> 00:04:00,666 Now you can check to see that it's here level four. 80 00:04:00,666 --> 00:04:01,633 Perfect. 81 00:04:01,633 --> 00:04:05,666 And now let's reselect this to rebuild our new polynomial regression 82 00:04:05,666 --> 00:04:07,700 model with this fourth degree. Now. 83 00:04:07,700 --> 00:04:11,633 So executing a new polynomial regression model created. 84 00:04:11,866 --> 00:04:13,833 And now let's have a look at the results. 85 00:04:13,833 --> 00:04:15,300 So these are the previous results 86 00:04:15,300 --> 00:04:19,066 corresponding to a polynomial regression model with a third degree. 87 00:04:19,066 --> 00:04:21,833 And now let's look at what happens with the fourth degree. 88 00:04:21,833 --> 00:04:24,966 So I'm going to select this and execute. 89 00:04:24,966 --> 00:04:28,300 And here are the polynomial regression results 90 00:04:28,300 --> 00:04:32,700 for a polynomial regression model with a fourth degree okay. 91 00:04:32,700 --> 00:04:35,533 So as you can see we can zoom on it if you want. 92 00:04:35,533 --> 00:04:36,300 As you can see 93 00:04:36,300 --> 00:04:40,133 the line is actually strictly passing by all the red observation points. 94 00:04:40,366 --> 00:04:43,766 And now the CEO would be even happier with the negotiation 95 00:04:43,766 --> 00:04:47,166 or should I say even less furious because the prediction 96 00:04:47,166 --> 00:04:50,833 now is actually almost the same as a real observation point. 97 00:04:50,900 --> 00:04:55,733 That is, the predicted salary is almost the same as the real salary. 98 00:04:56,633 --> 00:05:00,733 Okay, and same for our 6.5 level employee. 99 00:05:01,133 --> 00:05:05,166 When we project this 6.5 level here on the curve and then projected again 100 00:05:05,166 --> 00:05:09,233 on the Y axis, that is the salary axis, we get a value around what he said. 101 00:05:09,233 --> 00:05:11,100 That is 160 K. 102 00:05:11,100 --> 00:05:12,400 And for those of you who are interested 103 00:05:12,400 --> 00:05:15,400 in having a more continuous curve here, like we did in Python, 104 00:05:15,400 --> 00:05:19,033 I will add the code for that job in the R file provided in this section. 105 00:05:19,200 --> 00:05:20,400 You can check it out for fun. 106 00:05:20,400 --> 00:05:24,533 And this is the model we're going to use to get the accurate prediction 107 00:05:24,533 --> 00:05:26,433 of the previous salary of this new employee 108 00:05:26,433 --> 00:05:27,900 that is about to be hired, 109 00:05:27,900 --> 00:05:30,833 and we will compare it to the salary that it pretended 110 00:05:30,833 --> 00:05:32,866 to have in its previous company 111 00:05:32,866 --> 00:05:36,933 and eventually tell our final verdict whether it's truth or bluff. 112 00:05:37,500 --> 00:05:40,066 So I look forward to doing that with you in the next tutorial. 113 00:05:40,066 --> 00:05:41,866 And until then, enjoy machine learning.