1
00:00:01,370 --> 00:00:07,310
In the last video, we saw how to create Crinum forest classifier in Python.

2
00:00:08,510 --> 00:00:12,210
And if you remember, we provided several parameters.

3
00:00:13,200 --> 00:00:14,640
Two beloved Regnum for us.

4
00:00:15,810 --> 00:00:23,940
We provided a number of trees we want, and we also provided the default value of the number of variables

5
00:00:24,270 --> 00:00:25,350
we want to consider.

6
00:00:25,380 --> 00:00:28,470
For each three of the random forest.

7
00:00:29,930 --> 00:00:36,470
Their default value we used was a square root of the number of variables which comes out to be around

8
00:00:36,470 --> 00:00:37,370
four and five.

9
00:00:41,300 --> 00:00:48,260
So if I want to change the value of this hyper barometer's, I have to read on my whole code and then

10
00:00:48,260 --> 00:00:56,930
knock down the values of this accuracy or any other variable on which I am evaluating my model performance.

11
00:00:58,100 --> 00:00:58,940
So crying.

12
00:00:58,970 --> 00:01:04,640
Oh, different values of such hyper parameters will be a hectic task for us.

13
00:01:07,860 --> 00:01:14,670
To overcome this, Escalon provides us another function, which is great, sir S.V..

14
00:01:15,650 --> 00:01:23,090
And it's a CV, you can provide values of all the hyper parameters you want to consider for your more

15
00:01:23,090 --> 00:01:23,340
than.

16
00:01:25,570 --> 00:01:31,790
Then by 10:00, will automatically create model for each of such hyper parameter.

17
00:01:32,440 --> 00:01:39,790
And after that, you can select the model which provides the best accuracy score or any other evaluation

18
00:01:39,790 --> 00:01:40,390
parameter.

19
00:01:42,040 --> 00:01:45,100
So let's look at the documentation of research.

20
00:01:48,860 --> 00:01:52,580
We have to import grid search from as Skillern Todmorden selection.

21
00:01:54,240 --> 00:01:57,420
And then this are the parameters of grid search.

22
00:02:00,010 --> 00:02:02,110
The first one here is the estimated.

23
00:02:06,010 --> 00:02:11,480
Here you have to specify the model on which you want to change the hyper parameters.

24
00:02:12,160 --> 00:02:17,050
Since we want to give multiple Hyppolite, I went to this photo at Random Forest.

25
00:02:17,470 --> 00:02:20,870
So we will provide Regnum for us as estimated here.

26
00:02:22,060 --> 00:02:24,610
The next is the Padam under the sort of grid.

27
00:02:25,060 --> 00:02:28,530
This is an very important parameter here.

28
00:02:29,020 --> 00:02:37,120
You can mention the parameters and their values in the form of dictionary and grid search will automatically

29
00:02:37,120 --> 00:02:43,880
pick those parameters and create models using those hyper about their values.

30
00:02:46,510 --> 00:02:48,070
The next phase is scoring.

31
00:02:48,760 --> 00:02:51,400
So by default, your grid search.

32
00:02:51,490 --> 00:02:55,030
Use a cross-validation approach.

33
00:02:55,960 --> 00:03:04,300
That means that it will automatically take a segment of your data off your training data and calculate

34
00:03:04,720 --> 00:03:08,170
calculate the performance of your Morden using that data.

35
00:03:09,370 --> 00:03:15,300
So here you can provide that is scoring my word on how you want to select your final model.

36
00:03:16,450 --> 00:03:22,240
Since we are building a classification model, we will stick with accuracy as our scoring method.

37
00:03:23,830 --> 00:03:26,170
All other parameters are not important.

38
00:03:26,200 --> 00:03:26,750
If you want.

39
00:03:26,770 --> 00:03:29,380
You can go through each parameter as well.

40
00:03:31,970 --> 00:03:34,780
So let's go back and look at the code.

41
00:03:36,110 --> 00:03:39,060
First, we are creating our own name for this classifier.

42
00:03:40,280 --> 00:03:42,860
So we are just writing their name for this classifier.

43
00:03:43,220 --> 00:03:49,220
And here we are giving our hyper barometer as number of trees to be 250.

44
00:03:49,400 --> 00:03:54,500
And there are no Misato 42 so that we can reproduce the same results later on.

45
00:03:57,260 --> 00:04:04,760
Next, few remember, we have two more hyper barometers for our random forest there, days max features

46
00:04:05,330 --> 00:04:07,430
and minimum sample split.

47
00:04:10,180 --> 00:04:16,250
Max feature is the number of variables we want to consider while creating each individual tree.

48
00:04:16,600 --> 00:04:23,530
By default, this value is a square root of the number of variables which come so to be fought in our

49
00:04:23,530 --> 00:04:23,950
case.

50
00:04:24,580 --> 00:04:33,190
And here we want to crane our model for maximum feature value of four, five, six, seven, up to 10.

51
00:04:35,990 --> 00:04:39,940
The second hyper parameter we can change is minimum, simple split.

52
00:04:40,400 --> 00:04:45,650
So if you remember in Crete, there were three stopping our nation.

53
00:04:45,770 --> 00:04:47,080
That is maximum depth.

54
00:04:47,510 --> 00:04:56,660
The minimum number of observations required at internal load and minimum number of observations required

55
00:04:56,710 --> 00:04:57,650
at the leaf node.

56
00:04:58,160 --> 00:05:04,380
So this one here, minimum sample is split as the minimum number of observations required at 10 and

57
00:05:04,390 --> 00:05:05,120
then unknown.

58
00:05:07,480 --> 00:05:14,740
And here also we want to try out three values of minimum simple split, so we are giving two, three

59
00:05:14,770 --> 00:05:15,340
and 10.

60
00:05:18,150 --> 00:05:22,810
And if you see this bad grade is their dictionary.

61
00:05:23,670 --> 00:05:29,070
And if you remember, dictionaries consist of key value pair.

62
00:05:30,390 --> 00:05:37,710
So although we're hyper parameters will be keys and our values will be in the form of list of those

63
00:05:37,710 --> 00:05:38,640
hyper parameters.

64
00:05:38,670 --> 00:05:39,360
We want to give.

65
00:05:40,110 --> 00:05:49,650
So if you want to add any other variable to try out different values of their TypePad parameter, you

66
00:05:49,650 --> 00:05:54,480
can just put a comma and give a variable name here.

67
00:05:54,570 --> 00:06:02,130
So, for example, if I want to try out the end estimated value of two fifty five hundred and thousand,

68
00:06:02,370 --> 00:06:05,590
I can just provide an estimate that here.

69
00:06:06,090 --> 00:06:12,930
And I can provide values of two fifty five hundred and thousand in the form of the list of this key

70
00:06:12,930 --> 00:06:13,560
value pair.

71
00:06:15,120 --> 00:06:16,320
So let's run this.

72
00:06:18,850 --> 00:06:25,480
So as I told you earlier, for grid search, you have to wait for the classifier, our classifier is

73
00:06:25,480 --> 00:06:32,080
this random forest classifier that we created earlier than we have to provide the dictionary of all

74
00:06:32,080 --> 00:06:33,110
the hyper parameters.

75
00:06:33,160 --> 00:06:34,240
Well, do we want to try?

76
00:06:34,510 --> 00:06:36,570
So we have created this dictionary value.

77
00:06:36,760 --> 00:06:40,070
That's why we can radically provide under school grade.

78
00:06:40,780 --> 00:06:47,710
And then this end job minus one is to operate our model at the full efficiency of our laptop.

79
00:06:48,250 --> 00:06:50,490
Then C.V is for cross-validation.

80
00:06:50,800 --> 00:06:52,780
So we are giving it as five.

81
00:06:53,350 --> 00:06:56,440
And we want to escoto or model using accuracy

82
00:06:59,380 --> 00:07:00,850
just like any other model.

83
00:07:00,880 --> 00:07:02,170
We are saving this model.

84
00:07:03,050 --> 00:07:06,160
And another object that is good on that score to search.

85
00:07:07,030 --> 00:07:08,710
So let's run this.

86
00:07:09,820 --> 00:07:12,850
But before that, we have important grid search seewhy.

87
00:07:14,710 --> 00:07:17,770
It's important that and create this group set to object.

88
00:07:21,390 --> 00:07:27,800
And now, just like with any other classifier or regression object, you can do it extra and then by

89
00:07:27,820 --> 00:07:29,270
trying to turn to grid search.

90
00:07:31,970 --> 00:07:35,480
Since we are building so many models using this single come on.

91
00:07:35,600 --> 00:07:36,830
It will take some time.

92
00:07:39,020 --> 00:07:41,120
The number of models we are creating.

93
00:07:42,480 --> 00:07:46,590
It's the product of the number of individual hyper barometers we are providing.

94
00:07:46,620 --> 00:07:50,510
So here for maximum feature of four.

95
00:07:51,370 --> 00:07:59,250
We are building three model with minimum simple split off to three and then then again for maximum feature

96
00:07:59,250 --> 00:07:59,820
of five.

97
00:07:59,970 --> 00:08:05,310
We are building, again, three models, similarly for six.

98
00:08:05,340 --> 00:08:06,630
We are building three models.

99
00:08:06,780 --> 00:08:10,440
And for each of these values, we are building three, three, three models.

100
00:08:11,010 --> 00:08:15,900
So in total, we are building seven in two three models in this single.

101
00:08:15,900 --> 00:08:16,350
Come on.

102
00:08:18,390 --> 00:08:24,360
So you can see there is no need to manually enter hyper parameters each time.

103
00:08:25,230 --> 00:08:33,600
You can just provide them as a key value pair in their dictionary and you can run a grid search over

104
00:08:33,720 --> 00:08:36,750
all the parameters and their values.

105
00:08:40,020 --> 00:08:42,810
So we have green node 21 models.

106
00:08:45,400 --> 00:08:52,630
So this grid search here contained information of 21 models that we have created using this hyper parameter

107
00:08:52,630 --> 00:08:53,230
values.

108
00:08:54,190 --> 00:08:59,160
Now using cross-validation, we have also calculated that escort's of this.

109
00:08:59,170 --> 00:09:06,490
Twenty one more chance now to get the information of the best model that we have in this 21 model.

110
00:09:06,820 --> 00:09:13,430
You can call this best underscore bedtime's underscore attribute of grid search.

111
00:09:14,020 --> 00:09:17,020
So grid search comes with different attributes.

112
00:09:17,710 --> 00:09:21,850
And this is one of their tribute which will give you information of the best model.

113
00:09:23,510 --> 00:09:24,560
So just run this.

114
00:09:26,480 --> 00:09:32,840
You can see we are getting our best model when our maximum feature value is seven and minimum sample

115
00:09:32,840 --> 00:09:34,670
displayed is three feet.

116
00:09:35,050 --> 00:09:40,780
Remember, we use seven values of maximum feature and three values of minimum sample displayed.

117
00:09:41,300 --> 00:09:48,080
So out of the seven values of maximum feature, we are getting our best reserved at maximum feature

118
00:09:48,080 --> 00:09:53,340
equal to seven and out of this three values of minimum Symbolistic.

119
00:09:53,600 --> 00:09:56,660
We are getting our best result at minimum.

120
00:09:56,660 --> 00:09:58,220
Sample split as three.

121
00:10:02,290 --> 00:10:11,860
Now, to get this more than from 021 model, we can use best underscore estimates, underscore attribute

122
00:10:11,930 --> 00:10:12,820
of grid search.

123
00:10:13,510 --> 00:10:18,640
So this attribute here contains the information of our best model.

124
00:10:19,270 --> 00:10:24,670
So we are just creating another variable to get this information.

125
00:10:25,360 --> 00:10:31,570
And later on, we can use this C.V AALDEF underscore to see a lift variable to credit total values of

126
00:10:31,570 --> 00:10:32,010
best.

127
00:10:33,460 --> 00:10:34,600
So we will run this.

128
00:10:37,870 --> 00:10:42,330
No, no word S.V. R.F. underscore to see a left variable.

129
00:10:43,770 --> 00:10:50,160
Contains the model for which maximum featured is equal to seven and minimum, but split is equal to

130
00:10:50,160 --> 00:10:50,550
three.

131
00:10:50,940 --> 00:10:55,680
And this is the best model out of the 21 models we have created using it set.

132
00:10:58,020 --> 00:11:06,900
Now, to get the accuracy score on our test data, we can medically call a curious end of school function

133
00:11:07,380 --> 00:11:12,390
and we can use the Dort critic method to credit the values of why test.

134
00:11:12,900 --> 00:11:14,250
So let's run this.

135
00:11:18,160 --> 00:11:22,330
The accuracy is scored for our best model.

136
00:11:22,450 --> 00:11:29,770
All of this different values of hyper barometer's as zero one six three and you can also draw confusion,

137
00:11:29,770 --> 00:11:31,780
the matrix using the same technique.

138
00:11:35,260 --> 00:11:43,240
So this is just an example on how to pass multiple values of hyper parameter and get the best result

139
00:11:43,480 --> 00:11:45,690
out of all the hype at parameters values.

140
00:11:46,720 --> 00:11:50,510
You can write on your own, try providing more.

141
00:11:50,950 --> 00:11:58,840
I put parameters and their values in this part ended and tried to get the accuracy scored more than

142
00:11:58,840 --> 00:11:59,960
this accuracy score.

143
00:12:02,390 --> 00:12:08,550
So with grid search, there is no need to rerun your model again and again, you can use grid search

144
00:12:09,060 --> 00:12:12,270
to train multiple more than a single line of code.

145
00:12:13,470 --> 00:12:13,890
Thank you.
