1
00:00:00,660 --> 00:00:01,120
Hello.

2
00:00:01,140 --> 00:00:01,670
Welcome back.

3
00:00:01,980 --> 00:00:05,430
So let's see how to land from data practically.

4
00:00:05,570 --> 00:00:11,090
I'm gonna make a copy of our last project copy paste over here.

5
00:00:11,370 --> 00:00:13,150
I'll call this Pruett force land.

6
00:00:13,260 --> 00:00:21,030
And by the end of this uh this experiment you should understand how the um the model learns from data

7
00:00:21,090 --> 00:00:25,740
and updates the weight accordingly.

8
00:00:25,970 --> 00:00:27,730
Call this brute force learning.

9
00:00:27,730 --> 00:00:31,320
Like I said open it

10
00:00:35,370 --> 00:00:39,770
so there's our old project I'm going to create a new function here.

11
00:00:39,970 --> 00:00:40,420
You know why.

12
00:00:40,440 --> 00:00:45,030
Simple neural network that see fall in this function we shall use to demonstrate what we're talking

13
00:00:45,030 --> 00:00:45,320
about.

14
00:00:45,780 --> 00:00:50,770
So like we mentioned earlier learning is just it's just reducing error.

15
00:00:50,820 --> 00:01:00,150
Essentially it involves learning the difference between the um the predicted value and the expected

16
00:01:00,150 --> 00:01:06,440
value and adjust in our weight accordingly to reduce the error for the next prediction.

17
00:01:06,450 --> 00:01:13,090
So whenever you hear Len and you can simply think of reducing error or reducing loss.

18
00:01:13,110 --> 00:01:19,570
Often people say Lenin as simply reducing loss right.

19
00:01:19,710 --> 00:01:22,530
So I'm going to create a new function here.

20
00:01:22,560 --> 00:01:23,370
I'll see void

21
00:01:27,880 --> 00:01:29,140
let me show me in a bit for you.

22
00:01:34,190 --> 00:01:38,440
Brute force Lenin and this function.

23
00:01:38,540 --> 00:01:44,630
Let's say it takes five parameters so that you can change the parameters.

24
00:01:45,050 --> 00:01:51,080
The first parameter is an input.

25
00:01:51,080 --> 00:01:53,390
The second parameter is the weight

26
00:01:59,660 --> 00:02:04,930
the third parameter is the expected value.

27
00:02:10,000 --> 00:02:13,620
The fourth parameter is something that we call step amount.

28
00:02:14,200 --> 00:02:17,130
And we're going to pass an amount here.

29
00:02:17,140 --> 00:02:22,450
And this amount is going to be the amount that we increase the weight by.

30
00:02:22,450 --> 00:02:31,270
So based on the home based on the difference between the expected value and the and the predicted value

31
00:02:31,390 --> 00:02:37,780
we would decide whether we want to increase the weight or reduce the weight by this variable that we

32
00:02:37,780 --> 00:02:41,110
call step amount over here.

33
00:02:41,110 --> 00:02:43,630
Step amount.

34
00:02:43,630 --> 00:02:51,030
And the last argument is going to be number of iterations.

35
00:02:51,290 --> 00:02:54,070
This is often known as number of epochs.

36
00:02:54,070 --> 00:03:02,100
If you use a library such as carers or tens of flow so we're going to run the function.

37
00:03:02,110 --> 00:03:13,360
This number of times for me to learn right.

38
00:03:14,260 --> 00:03:18,780
Okay so we start off by computing our predicted value.

39
00:03:19,390 --> 00:03:26,170
And um we can start off by creating a local variable here to hold the predicted value.

40
00:03:26,230 --> 00:03:27,190
I'm gonna say double

41
00:03:31,170 --> 00:03:31,950
prediction.

42
00:03:31,970 --> 00:03:32,800
Hope other.

43
00:03:32,980 --> 00:03:44,290
And another variable code error and a self more double up prediction.

44
00:03:44,490 --> 00:03:49,770
We're gonna predict up and predict down storm prediction.

45
00:03:50,400 --> 00:03:52,200
And this was just for demonstration.

46
00:03:52,920 --> 00:04:00,140
Hopefully this will give you a clearer picture on the concept of learning in machine learning.

47
00:04:00,140 --> 00:04:02,720
So we have a prediction on prediction.

48
00:04:02,740 --> 00:04:06,330
Let's see another variable up error down.

49
00:04:06,330 --> 00:04:06,720
Error

50
00:04:12,120 --> 00:04:13,440
okay.

51
00:04:13,440 --> 00:04:14,030
Right.

52
00:04:14,040 --> 00:04:17,960
So once they start we're gonna open a full loop over here.

53
00:04:17,970 --> 00:04:21,630
Oh say for int i equals zero.

54
00:04:21,990 --> 00:04:25,610
I is less than I.

55
00:04:25,620 --> 00:04:30,710
It's less than a number of iterations.

56
00:04:30,900 --> 00:04:31,380
All right.

57
00:04:31,410 --> 00:04:38,860
Plus plus open and then close and we're gonna come over here and say

58
00:04:43,140 --> 00:04:50,250
prediction equals input multiplied by weight like this.

59
00:04:50,400 --> 00:05:03,080
And of course we can compute the error by saying error because we already have a function for compute

60
00:05:03,080 --> 00:05:05,900
an error but we can write it here.

61
00:05:06,150 --> 00:05:07,500
Power of prediction

62
00:05:10,070 --> 00:05:20,170
minus expected value or rich to the poor to cause we reason it to the power to so coma to

63
00:05:23,410 --> 00:05:24,250
right.

64
00:05:24,360 --> 00:05:30,980
So once that is done we can sort of print the arrow and prediction.

65
00:05:31,540 --> 00:05:35,800
So I'm gonna put a print off over here print f

66
00:05:41,130 --> 00:05:44,280
error percentage f

67
00:05:48,120 --> 00:05:48,870
prediction

68
00:05:51,300 --> 00:05:53,270
percentage f then

69
00:05:57,450 --> 00:06:02,040
and of course we simply need to pass error and prediction here

70
00:06:08,350 --> 00:06:10,340
right.

71
00:06:10,560 --> 00:06:16,410
So we will print the error in prediction once that is done we're gonna do up prediction and down prediction

72
00:06:16,470 --> 00:06:25,470
and we do a prediction by adding D step amount to the current weight value and then compute a new predicted

73
00:06:25,470 --> 00:06:37,690
value that will be the prediction and then we compute the error we get when we increase the weight.

74
00:06:38,120 --> 00:06:44,330
The reason we have this error is because we don't have access to a y you arts module in this in this

75
00:06:44,330 --> 00:06:45,150
file.

76
00:06:45,170 --> 00:06:50,840
So what I'm gonna do is over here you know I mean we often call the U of stone h I'm gonna cut this

77
00:06:51,670 --> 00:06:55,690
and I'm going to put it in the simple neural networks that H.

78
00:06:55,720 --> 00:07:03,450
Should we just call it was so pasted in here and the error should disappear.

79
00:07:03,450 --> 00:07:06,160
There is no more error here right.

80
00:07:06,230 --> 00:07:12,830
So we do this we do the prediction we calculate the arrow and then like I said we're going to increase

81
00:07:12,830 --> 00:07:18,740
the weight by the step amount and we shall call this r prediction and then calculate the up arrow and

82
00:07:18,740 --> 00:07:21,380
do the same for down and calculate it down arrow.

83
00:07:21,800 --> 00:07:34,390
So I say a prediction you input multiply by weight plus step amount

84
00:07:38,540 --> 00:07:39,590
and then up error

85
00:07:43,890 --> 00:07:50,030
then up arrow we say equals we compute error the same way.

86
00:07:50,090 --> 00:07:53,600
This time the predicted value is a prediction.

87
00:07:53,600 --> 00:08:01,450
So I'm just gonna copy this actually and this variable here becomes a prediction.

88
00:08:09,940 --> 00:08:11,770
Like this.

89
00:08:17,440 --> 00:08:19,730
Right.

90
00:08:19,900 --> 00:08:23,500
So because we reached to the poor to you.

91
00:08:23,560 --> 00:08:27,700
Then if we place expected value here and predicted value on the other side.

92
00:08:27,710 --> 00:08:32,420
Reason to the pope to sort of create an absolute value for us.

93
00:08:32,570 --> 00:08:33,010
Right

94
00:08:39,440 --> 00:08:40,960
so let's do don't prediction.

95
00:08:40,970 --> 00:08:50,900
I'm going to come over here.

96
00:08:52,300 --> 00:08:58,840
Don't prediction equals input times.

97
00:08:59,200 --> 00:09:00,390
Wait.

98
00:09:00,410 --> 00:09:01,040
Minus

99
00:09:06,240 --> 00:09:10,140
step amount and down.

100
00:09:10,140 --> 00:09:10,540
Error

101
00:09:13,420 --> 00:09:13,820
equals

102
00:09:20,190 --> 00:09:21,180
Storm Prediction

103
00:09:26,140 --> 00:09:30,020
minus expected value.

104
00:09:30,370 --> 00:09:35,040
Commentary like this.

105
00:09:41,670 --> 00:09:42,000
Right.

106
00:09:42,030 --> 00:09:43,400
So we have a prediction.

107
00:09:43,410 --> 00:09:45,610
And don't predict.

108
00:09:45,810 --> 00:09:48,280
So now we've got a steady direction.

109
00:09:48,390 --> 00:09:49,430
Right.

110
00:09:49,490 --> 00:09:55,980
What our goal or aim here is to reduce the error which is the difference between the predicted value

111
00:09:56,100 --> 00:09:58,560
and the expected value.

112
00:09:58,560 --> 00:10:04,800
And we've created some variables here known as a prediction and down prediction meaning we simply take

113
00:10:04,800 --> 00:10:11,160
the weight and we add a small amount to it and then we compute the error for that and then we take the

114
00:10:11,160 --> 00:10:17,460
weight again we add the same we subtract the same small amount from the weight and we compute the error.

115
00:10:17,460 --> 00:10:24,150
Now we're going to say that if the down arrow is less than the up arrow this means then we are in the

116
00:10:24,180 --> 00:10:25,780
right direction right.

117
00:10:25,980 --> 00:10:34,240
Cos the arrow the difference between the expected value on the and the predicted value when we subtracted

118
00:10:34,290 --> 00:10:39,150
something small from the weight is is better.

119
00:10:39,150 --> 00:10:44,780
The difference is smaller compared to the difference between the expected value and the predicted value.

120
00:10:44,790 --> 00:10:50,610
When we added something small to the weight so we want smaller difference meaning less error.

121
00:10:50,910 --> 00:10:57,930
So if down arrow is less than up arrow then we want to subtract again we keeps subtracting something

122
00:10:57,930 --> 00:11:01,580
small until we diminish the day the arrow.

123
00:11:01,590 --> 00:11:06,570
Ideally we want the error to be zero but we may not be able to achieve that we want it to be as small

124
00:11:06,570 --> 00:11:07,860
as possible.

125
00:11:07,860 --> 00:11:12,300
So I'm gonna say if down arrow is less than up.

126
00:11:12,300 --> 00:11:13,940
Error like this.

127
00:11:14,190 --> 00:11:24,030
If that's the case then we simply want to say wait a course wait minus step amount cos we are in the

128
00:11:24,030 --> 00:11:24,950
right direction.

129
00:11:25,050 --> 00:11:29,490
Let's subtract again and see if indeed it's gonna be even smaller.

130
00:11:29,490 --> 00:11:33,180
The area is gonna be smaller and we keep subtracting.

131
00:11:33,180 --> 00:11:35,620
So I'm gonna say Step amount over here.

132
00:11:36,030 --> 00:11:44,520
On the other hand if up if down arrow we can just keep down their own decide down arrow is greater than

133
00:11:44,580 --> 00:11:53,250
up arrow then up arrow which would add more cos the down arrow when we went to the down direction by

134
00:11:53,250 --> 00:11:55,390
subtracting the arrow became bigger.

135
00:11:55,410 --> 00:11:57,570
So we need to add more meaning to you.

136
00:11:57,630 --> 00:11:59,250
The answer is on the other side.

137
00:11:59,280 --> 00:12:00,780
So we need to add.

138
00:12:01,110 --> 00:12:01,880
I hope you get this.

139
00:12:01,880 --> 00:12:03,560
If you do not just send me a message.

140
00:12:04,590 --> 00:12:13,050
We say weight equals weight plus step hormones like this.

141
00:12:13,580 --> 00:12:14,400
Right.

142
00:12:14,880 --> 00:12:17,340
So we can expose the function now and try it out.

143
00:12:17,760 --> 00:12:19,500
I'm gonna copy this.

144
00:12:20,010 --> 00:12:21,720
Put it in the head of all over here

145
00:12:26,100 --> 00:12:27,910
and I'm going to go to the main file

146
00:12:32,950 --> 00:12:34,480
and I'm gonna clean everything here.

147
00:12:34,480 --> 00:12:37,970
Cause this from my previous projects and we don't need any of this.

148
00:12:37,990 --> 00:12:39,880
It's a very simple experiment

149
00:12:43,880 --> 00:12:48,700
und let's create some data here for testing our function.

150
00:12:48,730 --> 00:12:55,110
I'm gonna say double wait let's see the weight equals zero point five.

151
00:12:55,150 --> 00:12:56,640
That is a realistic weight.

152
00:12:57,950 --> 00:13:04,870
And when I see double input hobos you put five as well.

153
00:13:04,870 --> 00:13:08,200
Three point five over here and I'm going to see double

154
00:13:11,450 --> 00:13:15,120
expected value.

155
00:13:16,500 --> 00:13:21,270
Let's say the expected value which is the y value is zero point eight.

156
00:13:21,710 --> 00:13:26,060
And I'm going to say double step amount

157
00:13:29,690 --> 00:13:34,850
and I'm gonna see this the step I'm on this the amount we're going to be adding also trucked in from

158
00:13:34,850 --> 00:13:35,240
the weights.

159
00:13:35,250 --> 00:13:37,110
I'm going to see it 0.01.

160
00:13:37,220 --> 00:13:41,000
Sure point sure issue 1 right.

161
00:13:41,030 --> 00:13:44,060
So I'm going to call our function over here.

162
00:13:44,060 --> 00:13:49,950
The function is brute force learn in the first argument is the inputs.

163
00:13:50,180 --> 00:13:53,240
So pass inputs over here.

164
00:13:53,240 --> 00:13:57,560
The second argument is the weight past wage of here.

165
00:13:57,680 --> 00:14:03,050
The third argument is the expected value pass expected value over here.

166
00:14:05,710 --> 00:14:09,320
The next argument is this step amount of positive step amount Yeah.

167
00:14:09,340 --> 00:14:12,110
The last argument is the number of iterations.

168
00:14:12,190 --> 00:14:17,950
Let's say we want to run this for one thousand five hundred times right.

169
00:14:20,860 --> 00:14:21,580
So let's build

170
00:14:25,130 --> 00:14:30,110
um actually going to open to return first said I want it built and we download.

171
00:14:30,110 --> 00:14:37,210
We can see it from scratch rather than a research my board actually.

172
00:14:37,350 --> 00:14:38,230
Yeah.

173
00:14:38,430 --> 00:14:43,000
Terra term is going to be minimized if I click this window so let's just build.

174
00:14:43,100 --> 00:14:50,310
Yeah click over here to build your successfully Gary on the board.

175
00:14:51,340 --> 00:14:52,200
Okay.

176
00:14:52,270 --> 00:14:54,210
I'm gonna open to return.

177
00:14:58,340 --> 00:15:05,120
And this is where we have it's land in to remember the expected value we want is zero point eight.

178
00:15:05,210 --> 00:15:07,180
Let's see it run.

179
00:15:07,620 --> 00:15:08,930
It s still land in.

180
00:15:09,350 --> 00:15:10,940
And as you can see us it s last.

181
00:15:10,940 --> 00:15:16,120
The arrow reduces and we get closer and closer to the expected value.

182
00:15:16,190 --> 00:15:20,040
It s still learning it's still learning.

183
00:15:23,380 --> 00:15:29,540
Oh sorry bother minimized that we know but I hope you're running it on your side as well

184
00:15:33,050 --> 00:15:44,610
right.

185
00:15:44,790 --> 00:15:47,250
Okay now the error is 0.

186
00:15:47,260 --> 00:15:53,910
The expected value is the same as the predicted value but we are running it more than it's required.

187
00:15:53,920 --> 00:15:59,560
We said if you run for one thousand five hundred times that is why it's still running so we can wait

188
00:15:59,560 --> 00:16:00,410
for you to finish.

189
00:16:00,460 --> 00:16:00,820
Okay.

190
00:16:00,820 --> 00:16:02,800
It s done running now okay.

191
00:16:02,880 --> 00:16:03,380
This is it.

192
00:16:03,820 --> 00:16:07,000
So um oh advice you play around with it.

193
00:16:07,030 --> 00:16:16,390
You can change the parameters especially the um the number of iterations on the um and the step amount

194
00:16:17,050 --> 00:16:18,490
you can change it and see.

195
00:16:18,490 --> 00:16:22,030
Sometimes you get close to the expected value sometimes you don't.

196
00:16:22,030 --> 00:16:27,760
Sometimes you actually jump over the expected value so you can certainly try that right.

197
00:16:27,790 --> 00:16:30,360
And tell me how it goes.

198
00:16:30,550 --> 00:16:31,070
Okay.

199
00:16:31,120 --> 00:16:34,000
So this order is for this lesson and I'll see you later.
