1 00:00:00,780 --> 00:00:06,700 In this video, we will see how to train our model using shin gauge method. 2 00:00:07,870 --> 00:00:09,520 So we learn to shrinkage. 3 00:00:09,520 --> 00:00:11,310 Method one is rage. 4 00:00:11,410 --> 00:00:12,760 And one is lasso. 5 00:00:13,910 --> 00:00:15,790 So we'll be running the data first. 6 00:00:17,860 --> 00:00:18,820 Carondelet integration. 7 00:00:18,970 --> 00:00:22,060 We need to use a library called Delimit. 8 00:00:23,500 --> 00:00:27,830 So if you have it installed, you can find it here. 9 00:00:29,470 --> 00:00:35,070 It is delimit if you don't have if you don't have it installed, you can install it. 10 00:00:35,430 --> 00:00:36,760 I think installed packages. 11 00:00:37,920 --> 00:00:38,710 I have it installed. 12 00:00:38,760 --> 00:00:39,610 I just click it. 13 00:00:44,510 --> 00:00:50,780 Now for bridge division, we also need to segregate our data in two dependent very well and independent 14 00:00:50,780 --> 00:00:51,290 variables. 15 00:00:52,040 --> 00:00:55,610 So we'll create a separate variable called X. 16 00:00:56,580 --> 00:00:58,650 Which will get all the independent variables. 17 00:00:58,740 --> 00:01:02,850 So we'll wait X is equal to model matrix. 18 00:01:06,360 --> 00:01:09,630 Moral matrix and price. 19 00:01:12,730 --> 00:01:13,450 Lot dot 20 00:01:16,180 --> 00:01:26,580 com and they basically be and after this in squared Blackett, we were delayed that we do not want deep 21 00:01:26,580 --> 00:01:30,500 price Kollam so place Calame was the first column. 22 00:01:31,060 --> 00:01:37,180 So after this comma, we'll write minus one so that we do not get the price column. 23 00:01:37,720 --> 00:01:38,540 Next on this. 24 00:01:40,240 --> 00:01:43,180 So X as 15 variables. 25 00:01:43,270 --> 00:01:46,590 It does not have the sixteenth variable we just place. 26 00:01:47,290 --> 00:01:48,950 If you want to look at it, you can click on it. 27 00:01:49,450 --> 00:01:50,350 But let's move forward. 28 00:01:51,490 --> 00:01:55,060 Now we will create a Y variable which will have the dependent variable. 29 00:01:55,750 --> 00:02:00,610 So I do have Y is equal to the F dollar price. 30 00:02:04,620 --> 00:02:08,100 So now X has all these independent videos. 31 00:02:08,250 --> 00:02:09,790 Why has the dependent variable? 32 00:02:10,950 --> 00:02:15,330 Now, if you remember in digitization there is an added parameter called lambda. 33 00:02:15,840 --> 00:02:21,030 And we want to find out that critical lambda for which the edit is minimum. 34 00:02:22,350 --> 00:02:30,360 So really create a grid of lambdas and we'll run the model for all those lambdas and we'll then find 35 00:02:30,540 --> 00:02:32,970 the lambda, which has the lowest added. 36 00:02:34,440 --> 00:02:37,500 So to do that, we will rate grade is equal to. 37 00:02:39,720 --> 00:02:46,800 And there's two part sequence in common, minus two. 38 00:02:47,610 --> 00:02:49,680 At first plaited, I'll explain it in a bit. 39 00:02:51,200 --> 00:02:54,590 So then come on, minus two comma length is equal 200. 40 00:02:59,400 --> 00:03:00,420 Is equal 200 hundred. 41 00:03:07,130 --> 00:03:15,380 Next on this, no, let us look at this grid variable, will they Grid and Bressington? 42 00:03:20,390 --> 00:03:27,840 You can see that it has undervalues since we told that we want to Lindop hundred and it starts, Fred. 43 00:03:28,260 --> 00:03:37,010 And it's about 10 because TNT first value and it will end at ingestible minus two because that was the 44 00:03:37,010 --> 00:03:40,010 end point within the this range. 45 00:03:40,610 --> 00:03:45,560 It has divided this range of 10 to minus two in 200 different values. 46 00:03:46,190 --> 00:03:50,630 And for all those value, we have a grade of 10 this two part that value. 47 00:03:52,140 --> 00:03:58,400 So this is the value of lambda it very spontaneous, about 10, which is very high, number two, Tanaiste, 48 00:03:58,440 --> 00:04:00,660 but minus two, which is a very small lambda. 49 00:04:02,940 --> 00:04:05,960 So we have a grade of lambdas now. 50 00:04:06,650 --> 00:04:15,660 We are going to put these lambed does this X and this way into our model, so we'll create a lemon discourage. 51 00:04:19,810 --> 00:04:22,150 Is equal to GLAAD. 52 00:04:22,590 --> 00:04:23,000 Nick. 53 00:04:25,450 --> 00:04:32,510 And within bracket will rate X, comma, Y, comma, I'll fight equal to zero. 54 00:04:33,740 --> 00:04:34,130 This better. 55 00:04:34,340 --> 00:04:38,940 I'll fight takes two values, zero for reintegration and one for the lasso. 56 00:04:40,550 --> 00:04:43,730 And the last bet I made that is lambda, which will be equal to grade. 57 00:04:46,950 --> 00:04:48,390 So there us is this. 58 00:04:54,650 --> 00:05:02,270 So we have elements does Ridge as a variable, we can look at a summary of this created model, but 59 00:05:02,600 --> 00:05:04,050 it won't make much sense to us. 60 00:05:09,050 --> 00:05:15,920 The first thing we want to find out from this is the critical value of LAMDA for which we have the best 61 00:05:15,920 --> 00:05:16,300 model. 62 00:05:18,340 --> 00:05:23,560 Glue that we need to compare the R-squared values or some barometer like that. 63 00:05:24,910 --> 00:05:29,380 So DNA really gives us the option to use cross-validation. 64 00:05:30,580 --> 00:05:32,860 So it has a inbuilt cross-validation function. 65 00:05:33,460 --> 00:05:38,140 We'll be using that to find out the best lambda clue that will wait. 66 00:05:38,500 --> 00:05:39,810 S.V. Underscore, Rick. 67 00:05:42,670 --> 00:05:47,250 It get CVD out the eliminate. 68 00:05:51,510 --> 00:05:53,920 X.com and Viacom are all physical digital. 69 00:06:05,300 --> 00:06:07,700 And the last parameter is less magical low-grade. 70 00:06:20,120 --> 00:06:22,050 And now we'll look at this. 71 00:06:22,140 --> 00:06:23,990 See if it will rain blood. 72 00:06:26,640 --> 00:06:28,660 And within brackets relate S.V. Fit. 73 00:06:41,330 --> 00:06:50,060 You can see this is a graph of log values of lambda against the mean square amongst all these means 74 00:06:50,060 --> 00:06:51,050 good at our values. 75 00:06:51,440 --> 00:06:55,040 We want to find the point where they mean squared error is lowest. 76 00:06:55,790 --> 00:06:57,230 And corresponding to that point. 77 00:06:57,530 --> 00:06:59,070 You want to find the lambda value. 78 00:07:00,020 --> 00:07:07,460 So you can see from this graph it seems to be somewhere here or let us find the optimal value lambda 79 00:07:09,080 --> 00:07:12,890 to find that optimum value of lambda will rate optimum. 80 00:07:12,890 --> 00:07:17,000 Lambda OPB underscore lambda. 81 00:07:20,270 --> 00:07:22,530 Yet S.V. underscored for. 82 00:07:26,690 --> 00:07:28,550 Dollard Lamda Mean. 83 00:07:34,120 --> 00:07:38,470 So for the S.V. fit very well, it has all the lambdas. 84 00:07:39,130 --> 00:07:45,880 We are taking our day lamda for which deman means water that is minimum to let us run this formula. 85 00:07:47,600 --> 00:07:51,150 So we have a new variable called Optimum Lambda created here. 86 00:07:52,490 --> 00:07:59,630 So this optimum lambda, this now has the value of lambda for which our mean square error is lowest. 87 00:08:01,400 --> 00:08:07,100 If you want to find out, because funding R-squared value of the model, there are optimum lamda is 88 00:08:07,100 --> 00:08:07,580 this. 89 00:08:08,630 --> 00:08:10,520 We have to write a couple of lines of code. 90 00:08:11,210 --> 00:08:19,040 So first thing we need to find is the total to Moscowitz, which is VSS get. 91 00:08:21,870 --> 00:08:22,290 Some. 92 00:08:24,410 --> 00:08:26,250 I went in bracket 93 00:08:28,650 --> 00:08:31,250 differential, actual away from the mean. 94 00:08:32,160 --> 00:08:32,950 So mean why? 95 00:08:38,660 --> 00:08:42,020 And this all defense to be squared. 96 00:08:42,320 --> 00:08:44,760 So we'll put a date to. 97 00:08:47,030 --> 00:08:52,430 So we will run this and we'll get it to assess witchetty total Thomas squirts. 98 00:08:53,420 --> 00:08:58,640 Now we want to find out, do they do it's almost gourdes or that we need to find the predicted value 99 00:08:58,640 --> 00:09:00,190 of way from this fate. 100 00:09:02,150 --> 00:09:07,550 So we'll first find you predicted values, a way to get that the right way and just go to a. 101 00:09:10,750 --> 00:09:13,460 Get predict. 102 00:09:16,730 --> 00:09:17,900 L.M. underscore discourage. 103 00:09:23,720 --> 00:09:26,630 Comma s is equal to optimum lambda. 104 00:09:28,340 --> 00:09:34,490 So the lambda value that we have, the utility of doing lambda that we are so eligible to optimum lambda. 105 00:09:38,640 --> 00:09:48,180 And the x value to be used are the new X is equal to the x ray variable that we had created earlier 106 00:09:48,380 --> 00:09:49,190 to let us run it. 107 00:09:54,510 --> 00:09:56,110 So now we have the predicted values. 108 00:09:56,310 --> 00:10:00,500 Now we want to get these let's do to Moscowitz date. 109 00:10:00,660 --> 00:10:03,660 RSS is equal to some. 110 00:10:05,470 --> 00:10:10,360 And let me sum of different squared of the difference of predicted from actual. 111 00:10:10,970 --> 00:10:11,290 So. 112 00:10:12,810 --> 00:10:18,890 Difference of predicted by underscoring minus the actual. 113 00:10:18,950 --> 00:10:19,490 Which is why. 114 00:10:23,210 --> 00:10:24,090 I mean, it's credit. 115 00:10:25,800 --> 00:10:26,880 So next on this. 116 00:10:30,310 --> 00:10:31,700 And now we have this as value. 117 00:10:32,680 --> 00:10:33,070 So. 118 00:10:34,240 --> 00:10:38,020 Our square is VSS minus Orissa's by diocese. 119 00:10:38,880 --> 00:10:43,520 In other words, it is one minus auditors, but diocese to legislate that formula. 120 00:10:45,690 --> 00:10:54,510 R-squared rescue is equal to when minus are accessed by DS. 121 00:11:00,740 --> 00:11:06,020 So you can see the R-squared value for this model is coming out three point seven one nine six. 122 00:11:07,340 --> 00:11:10,220 So you can use this value to compare the model to. 123 00:11:12,130 --> 00:11:16,960 So this is how we first find out, do you fit using delimit? 124 00:11:19,140 --> 00:11:26,090 To get debate optimally of LAMDA, we will use the cross-validation function c.v or delimit ill plotted 125 00:11:26,170 --> 00:11:29,700 will find the minimum lamda will use this minimum lamda. 126 00:11:30,350 --> 00:11:38,720 And this previously fitted model to get the predicted riluzole predicted values of way using those predicted 127 00:11:38,720 --> 00:11:39,260 values over. 128 00:11:39,320 --> 00:11:44,930 We can always find out the means Guiterrez, RSS, VSS and all of those things. 129 00:11:46,370 --> 00:11:49,370 So this is how this integration is done. 130 00:11:50,060 --> 00:11:51,350 LASO is exactly same. 131 00:11:51,590 --> 00:11:56,540 Only that this parameter, which is Alpha, instead of being zero, it will be one. 132 00:11:57,400 --> 00:11:59,210 So let us out on a limb. 133 00:11:59,270 --> 00:12:00,230 Underscore Lassalle. 134 00:12:04,710 --> 00:12:06,780 Is equal to eliminate. 135 00:12:07,980 --> 00:12:08,580 Exactly same. 136 00:12:08,620 --> 00:12:09,510 Will copy pasted. 137 00:12:16,550 --> 00:12:21,810 Instead of this veto will do as one done and all the other stepped out. 138 00:12:21,860 --> 00:12:22,640 Exactly same. 139 00:12:23,060 --> 00:12:27,890 We can get the optimum Lambda for desautel using following the same steps. 140 00:12:28,760 --> 00:12:35,060 And from that optimum lambda, we can find out the predicted values away and then get these Askwith. 141 00:12:35,450 --> 00:12:37,040 You can compare these two R-squared. 142 00:12:38,750 --> 00:12:44,850 And that will tell you which of these two matters is giving us the more prediction, accuracy amongst 143 00:12:44,940 --> 00:12:45,900 LASO Enbridge. 144 00:12:48,200 --> 00:12:51,790 So this is all we do, lasso and integration and our.