1
00:00:00,360 --> 00:00:01,060
OK.

2
00:00:01,260 --> 00:00:07,260
Now we've made a copy of our original data frame we can start to edit DFT temp without any worries of

3
00:00:07,260 --> 00:00:08,960
damaging our original data.

4
00:00:09,000 --> 00:00:12,990
So if we ever needed to revert back to it we can with no troubles at all.

5
00:00:12,990 --> 00:00:18,720
So what we're going to do in this video is we're gonna take these dates.

6
00:00:18,720 --> 00:00:25,780
We're going to use pandas day time as well as some pandas date time attributes to enrich our dataset.

7
00:00:25,830 --> 00:00:30,900
And if you're wondering what is Daniel talking about enrich our data set while there's little practice

8
00:00:30,900 --> 00:00:34,260
that we're about to dive into it's called feature engineering.

9
00:00:34,260 --> 00:00:37,220
If you remember right back up in step four.

10
00:00:38,010 --> 00:00:39,880
Well we've covered a lot already.

11
00:00:39,930 --> 00:00:43,100
We've got a whole bunch of features and these are all listed here.

12
00:00:43,200 --> 00:00:48,210
What feature engineering means is it creating a new feature.

13
00:00:48,210 --> 00:00:53,880
So something like usage band may be completely different to usage man but we were just added on here

14
00:00:54,060 --> 00:01:00,570
and then that could be a description or we would dive into one of these and go sale date and we change

15
00:01:00,570 --> 00:01:01,910
it around a little bit.

16
00:01:01,980 --> 00:01:04,530
So that's the process of feature engineering so let's do that.

17
00:01:04,530 --> 00:01:05,830
But with the dates.

18
00:01:05,880 --> 00:01:07,260
Now how can we do that.

19
00:01:07,260 --> 00:01:11,230
Well first of all we're going to see it in action then we're going to discuss what's happening.

20
00:01:11,310 --> 00:01:15,690
This is something you might want to do for almost any time series project you're working on.

21
00:01:16,350 --> 00:01:21,660
So let's make a little heading here and date time parameters for sale date column.

22
00:01:22,080 --> 00:01:29,250
Wonderful and pandas has a beautiful little pandas date time.

23
00:01:29,280 --> 00:01:31,640
Well I just did pandas data.

24
00:01:31,630 --> 00:01:35,710
I'm going to trigger happy date time attributes this is what we're going to be using right.

25
00:01:36,180 --> 00:01:40,320
We've turned our sale date column into a date time index.

26
00:01:40,440 --> 00:01:47,280
See there immutable in the array of data on data what we can do now is access some attributes of that

27
00:01:47,280 --> 00:01:48,440
date.

28
00:01:48,520 --> 00:01:50,340
This is what I mean here.

29
00:01:50,390 --> 00:01:55,980
So we can go year the year of that date time the month the day the hour the minute the second the microsecond

30
00:01:55,980 --> 00:01:57,240
nano second.

31
00:01:57,240 --> 00:01:57,720
Far out.

32
00:01:57,720 --> 00:01:59,310
That's that's getting pretty deep.

33
00:01:59,310 --> 00:02:00,430
Is it the start of the month.

34
00:02:00,450 --> 00:02:01,530
Is it the end of the month.

35
00:02:01,530 --> 00:02:03,150
Is it the start of a quarter.

36
00:02:03,150 --> 00:02:09,180
Now I want you to think about why might this value these features be viable just without even seeing

37
00:02:09,180 --> 00:02:13,960
it without even coding it up if you're making a sale.

38
00:02:14,060 --> 00:02:21,410
Why would it be a good idea to maybe know whether or not it was the end of a quarter or the start of

39
00:02:21,410 --> 00:02:23,660
a quarter or the start a month or something like that.

40
00:02:24,080 --> 00:02:26,100
Why would it be now.

41
00:02:26,120 --> 00:02:31,900
It's okay if you're unsure but this is part of being a data scientist or a machine learning engineer.

42
00:02:31,900 --> 00:02:34,370
Right it's about knowing a little bit about everything.

43
00:02:34,850 --> 00:02:39,500
So if you're working on time series sales maybe it's a good idea to know whether it's the start of a

44
00:02:39,500 --> 00:02:45,260
quarter because sales might be increasing because it's the start of quarter or maybe it's the end of

45
00:02:45,260 --> 00:02:48,760
a quarter and sales are going down because everyone's tied on budget.

46
00:02:49,120 --> 00:02:53,510
And maybe if it's the start of the year no one wants to buy anything but it's the end of the year and

47
00:02:53,510 --> 00:02:59,060
people are like oh yes let's let's use the rest of our budget let's buy heaps of things you don't have

48
00:02:59,060 --> 00:03:05,390
to know in-depth knowledge this is just a one thing you can do to enrich your date time objects.

49
00:03:05,420 --> 00:03:08,710
So let's go in here how can we do this.

50
00:03:08,710 --> 00:03:14,980
We can add a column what we can do is add a date time parameter for the sale date column on the end

51
00:03:15,040 --> 00:03:16,520
of our DFT help.

52
00:03:16,570 --> 00:03:21,010
And now again talking about it isn't as good as having a look.

53
00:03:21,010 --> 00:03:24,040
So we're going to say oh yea and how would we do this.

54
00:03:24,040 --> 00:03:32,140
So what we're doing here is we're making a column DFT hemp sale year Eagles def Tim sale date.

55
00:03:32,140 --> 00:03:38,410
So this means we're accessing the sale date column and then we can access the date time part of Saturday

56
00:03:38,440 --> 00:03:40,030
by using D.T..

57
00:03:40,270 --> 00:03:47,130
So DTV date time and then we can access the year attribute by putting diet year.

58
00:03:47,140 --> 00:03:48,500
So let's have a look at this.

59
00:03:48,520 --> 00:03:50,190
What does this tell us.

60
00:03:50,350 --> 00:03:53,610
Daytime indexed or what year the year of the date time.

61
00:03:53,710 --> 00:03:53,980
Mm hmm.

62
00:03:55,450 --> 00:04:00,640
Before we even reassign a column let's just take the first row and see what this does.

63
00:04:00,700 --> 00:04:02,290
Nineteen eighty nine.

64
00:04:02,320 --> 00:04:02,910
Okay.

65
00:04:03,110 --> 00:04:10,570
Now let's do the same again but let's do it with Day okay 17.

66
00:04:11,220 --> 00:04:11,690
All right.

67
00:04:11,740 --> 00:04:14,190
And now if we just did it with nothing.

68
00:04:14,290 --> 00:04:17,550
So if we just did the sale day.

69
00:04:17,860 --> 00:04:18,460
There we go.

70
00:04:18,460 --> 00:04:21,240
So we see that that's access the year that's access today.

71
00:04:21,250 --> 00:04:27,190
So let's enrich our data frame with a few columns pertaining to these different values and if you're

72
00:04:27,360 --> 00:04:28,140
not sure what I mean.

73
00:04:28,150 --> 00:04:29,590
Let's let's see in an action.

74
00:04:29,590 --> 00:04:39,940
If in doubt run the code sale year equals that and then what we might do is we might just do month day

75
00:04:40,240 --> 00:04:41,610
day of week day of year.

76
00:04:42,040 --> 00:04:47,590
And of course we could do more but in the essence of time really we can make a function that does basically

77
00:04:47,590 --> 00:04:48,250
all of these.

78
00:04:48,250 --> 00:04:52,020
But what we're going to do is just do five or six to demonstrate.

79
00:04:52,120 --> 00:04:53,560
So let's do that.

80
00:04:53,710 --> 00:04:55,720
We could copy it but we're going to practice coding it out.

81
00:04:55,870 --> 00:05:08,080
So we go here say all month equals DL temp dot sale date tab order complete a month and DL temp sale

82
00:05:08,080 --> 00:05:20,350
day equals the Tampa sale date DTA day DL temp and we're going to go sale day of week.

83
00:05:20,360 --> 00:05:24,460
And that was when we said day of week Can you read that.

84
00:05:24,650 --> 00:05:34,840
I mean we did camel case beautiful acres DLF temp dot say sale date dot EDT dot day of week the temp

85
00:05:35,890 --> 00:05:41,020
sale day of year equals def temp.

86
00:05:41,020 --> 00:05:43,510
Now as you can see there's a lot of redundant code here.

87
00:05:43,540 --> 00:05:45,210
There might be a function in there somewhere.

88
00:05:45,220 --> 00:05:49,600
That's a good challenge for you is to see if you can function like this and maybe even go to the panda's

89
00:05:49,600 --> 00:05:55,200
documentation and add a few more different parameters to it to enrich our data set.

90
00:05:55,410 --> 00:05:59,070
And now what do you think that this might do well let's have a look.

91
00:05:59,180 --> 00:06:03,100
We'll run that and then we'll go here def 10.

92
00:06:03,200 --> 00:06:07,120
We're going to view the head and we'll transpose it so we can see all the columns.

93
00:06:07,130 --> 00:06:09,710
Let's go right down the bottom.

94
00:06:09,980 --> 00:06:11,200
There we go.

95
00:06:11,210 --> 00:06:15,190
So what we've done is we've created so see here.

96
00:06:15,210 --> 00:06:21,750
So a year seven months our day Soledad we sell today of year we've created these five columns.

97
00:06:21,970 --> 00:06:27,050
And what it's done is it just taken the sale date and extracted some of those values and added them

98
00:06:27,050 --> 00:06:29,900
as more features on the back end of our data frame.

99
00:06:29,900 --> 00:06:35,300
Now of course these features won't be listed in our data dictionary but if we were to go in and share

100
00:06:35,300 --> 00:06:39,320
this with someone else maybe that would be something we add to the data dictionary but we won't do that

101
00:06:39,320 --> 00:06:40,680
for now.

102
00:06:40,750 --> 00:06:47,900
And so with this information here we probably don't need the sale date column anymore this one here

103
00:06:48,020 --> 00:06:49,640
probably a bit excess now.

104
00:06:49,670 --> 00:06:53,040
So what we might do is remove that.

105
00:06:53,060 --> 00:06:54,650
So let's drop it.

106
00:06:54,650 --> 00:06:57,860
So we'll put it in here a little comment.

107
00:06:57,860 --> 00:07:04,690
Now we've enriched our data frame and remember because we're working on 10 if we ever needed to sell

108
00:07:04,690 --> 00:07:05,480
date column back.

109
00:07:05,480 --> 00:07:11,750
We could just go back to our ADF our original data frame that we we imported now have enriched our data

110
00:07:11,750 --> 00:07:15,890
frame with date time features.

111
00:07:15,950 --> 00:07:19,060
We can remove Saturday.

112
00:07:19,790 --> 00:07:30,470
Let's go DFT Tam dot drop and we're going to go south right on axis equals 1 in place Eagles true.

113
00:07:30,530 --> 00:07:34,280
Remember in-place happens in place so we don't have to go DFT equals

114
00:07:36,970 --> 00:07:37,570
wonderful.

115
00:07:37,570 --> 00:07:42,400
Now if we tried to do this we're going to get an error because SDI doesn't exist anymore but that is

116
00:07:42,400 --> 00:07:48,240
okay because we've got the information it's just now across five different columns then and then then

117
00:07:48,300 --> 00:07:48,790
boom.

118
00:07:48,910 --> 00:07:56,630
And if we ever wanted to back we'd go back to our original data frame now I also want to check the values

119
00:07:57,710 --> 00:07:58,650
of different columns.

120
00:07:58,660 --> 00:08:04,490
Now this is all about HDI Rod and exploratory data analysis is just really checking out what's happening

121
00:08:04,640 --> 00:08:06,180
and what we might do.

122
00:08:06,230 --> 00:08:06,950
So let's pick one

123
00:08:09,950 --> 00:08:10,980
what do we got here.

124
00:08:12,440 --> 00:08:14,520
How about state.

125
00:08:14,530 --> 00:08:18,500
US state in which sale occurred wondered which state has the most sales.

126
00:08:18,500 --> 00:08:23,900
If you're from the US whatever state you're in direct in a direction you've made the most sense.

127
00:08:24,590 --> 00:08:26,750
Let's have a look.

128
00:08:26,780 --> 00:08:29,790
Value counts maybe it's gonna be Wyoming.

129
00:08:29,980 --> 00:08:35,650
No Florida Texas a lot of a lot of sales are happening Wow.

130
00:08:35,850 --> 00:08:36,340
OK.

131
00:08:36,470 --> 00:08:40,100
So Washington does why Wyoming even have a single sale

132
00:08:43,690 --> 00:08:46,230
I can't see it and at least maybe you can.

133
00:08:46,270 --> 00:08:46,690
There we go.

134
00:08:46,720 --> 00:08:48,100
Wyoming.

135
00:08:48,640 --> 00:08:50,200
One thousand six hundred seventy two.

136
00:08:50,240 --> 00:08:52,020
Okay so this another part of.

137
00:08:52,030 --> 00:08:53,620
You could check more columns if you want.

138
00:08:53,620 --> 00:08:56,080
You could go through and check different value accounts.

139
00:08:56,170 --> 00:08:58,010
Remember value Kansas is really handy.

140
00:08:58,030 --> 00:09:00,210
This is you're just looking at the spread of data.

141
00:09:00,250 --> 00:09:06,880
That's another way of looking at the distribution only tired of of exploring the data let's do modelling.

142
00:09:07,780 --> 00:09:11,830
Yeah let's do that and that's why more fun building a machine learning model.

143
00:09:11,980 --> 00:09:14,910
So I've done enough.

144
00:09:15,200 --> 00:09:18,400
I could always do more.

145
00:09:19,090 --> 00:09:27,640
But let's start to do some model driven 88 now.

146
00:09:27,940 --> 00:09:30,730
What is model driven 88.

147
00:09:30,790 --> 00:09:36,550
Well because there's so many features here we could spend all day just going through each of these columns

148
00:09:36,880 --> 00:09:43,330
finding the value counts doing a distribution floor making more plots but at the end of the day we kind

149
00:09:43,330 --> 00:09:45,040
of know what our valuation metric is.

150
00:09:45,040 --> 00:09:48,610
So why don't we try and just head towards that see and if we can.

151
00:09:48,610 --> 00:09:51,030
Well how would we build a model.

152
00:09:51,640 --> 00:09:54,480
Let's build a machine learning model.

153
00:09:54,490 --> 00:09:57,110
But member what are we trying to do.

154
00:09:57,130 --> 00:09:59,800
Well if we come back let's check data frame.

155
00:10:01,500 --> 00:10:07,820
We're trying to use all of the independent variables to predict sale price.

156
00:10:07,940 --> 00:10:08,490
All right.

157
00:10:09,210 --> 00:10:14,790
So that means if we just drop all the columns drop Sal Price that should be out x and then if we use

158
00:10:14,790 --> 00:10:17,820
Sal Price the column itself that should be our y.

159
00:10:17,820 --> 00:10:19,890
But what kind of machine learning model do we use.

160
00:10:19,890 --> 00:10:29,870
Well remember we've got psychic line machine learning math if we go here choosing the right estimate.

161
00:10:30,180 --> 00:10:32,970
And this is our all faithful.

162
00:10:32,970 --> 00:10:37,170
So if we were to start here if we go through this do we have above 50 samples.

163
00:10:37,170 --> 00:10:37,660
Yes.

164
00:10:37,660 --> 00:10:38,780
Are we predicting category.

165
00:10:38,780 --> 00:10:40,700
No predicting a quantity.

166
00:10:40,710 --> 00:10:42,690
Yes we are predicting a number.

167
00:10:42,750 --> 00:10:44,580
We are doing a regression problem.

168
00:10:44,700 --> 00:10:49,150
Now if we were to follow this through we've got a bunch of different model options here in the green.

169
00:10:49,290 --> 00:10:56,370
But because we already had some experience with random forest a random forest classifier that is what

170
00:10:56,370 --> 00:11:00,960
we might do is checking out its counterpart the Random Forests regress.

171
00:11:01,560 --> 00:11:07,680
So if we were to go through here forests to randomize trees there's a classifier and there's random

172
00:11:07,680 --> 00:11:09,270
forest regress.

173
00:11:09,310 --> 00:11:09,690
All right.

174
00:11:10,590 --> 00:11:12,810
Well let's see what we can do.

175
00:11:12,840 --> 00:11:16,350
We've seen this before with psychic line of how to import a model.

176
00:11:16,350 --> 00:11:22,590
So if we go from S line dot ensemble and remember if you want to see exactly how to do this you could

177
00:11:22,590 --> 00:11:24,780
just go into here random forest regress.

178
00:11:25,470 --> 00:11:26,790
And then I'll tell you what to do.

179
00:11:26,820 --> 00:11:29,800
There might even be an example down here.

180
00:11:30,050 --> 00:11:33,500
There we go from SCA learned on ensemble import random forest regress.

181
00:11:33,500 --> 00:11:34,360
That's what we're gonna do.

182
00:11:35,360 --> 00:11:39,070
Import random forest regress.

183
00:11:39,110 --> 00:11:41,960
Paul this is exciting we're getting into modeling already.

184
00:11:41,960 --> 00:11:46,790
Well instantiate a model so model equals random forest regress.

185
00:11:47,600 --> 00:11:51,330
And we're going to set the number of jobs to equal negative 1.

186
00:11:51,350 --> 00:11:52,160
What does this mean.

187
00:11:52,160 --> 00:11:57,320
Well that means it's going to use as many cause as possible on my computer because we're dealing with

188
00:11:57,770 --> 00:12:00,240
how many rows are we dealing with DFT.

189
00:12:01,000 --> 00:12:07,310
We want the len we're dealing a four hundred and twelve thousand rows so that means our machine learning

190
00:12:07,310 --> 00:12:14,720
model has to go through four hundred twelve thousand plus rows of this try to work out all the patterns

191
00:12:14,750 --> 00:12:18,040
between these columns and then try and calculate Sal Price.

192
00:12:18,050 --> 00:12:18,630
That's a lot.

193
00:12:19,040 --> 00:12:28,090
And what we might also do from now on is remember how we used to set we could do this any random seed

194
00:12:28,170 --> 00:12:29,070
42.

195
00:12:29,110 --> 00:12:31,820
We could set that in all of our cells.

196
00:12:31,960 --> 00:12:35,820
But another way to do it is with our models there's a there's a parameter called random state.

197
00:12:35,830 --> 00:12:44,640
We can go equals 42 and remember to check the documentation of what's going on oh have we not a I can't

198
00:12:44,640 --> 00:12:46,120
press shift tab for some reason.

199
00:12:46,680 --> 00:12:48,710
I'll just go to the documentation here.

200
00:12:48,810 --> 00:12:53,340
We'll see what random state means.

201
00:12:53,340 --> 00:12:53,820
Here we go.

202
00:12:53,820 --> 00:12:59,040
Controls both the randomness of the bootstrapping of the samples when used when building trees.

203
00:12:59,040 --> 00:13:03,190
If bootstrapping was true and the sampling of the features to consider okay.

204
00:13:03,280 --> 00:13:05,000
So long story short this is going to.

205
00:13:05,000 --> 00:13:10,870
It acts like any random seed and if we go here and jobs there we go.

206
00:13:11,010 --> 00:13:15,100
None means one unless job lab negative one means using all processes.

207
00:13:15,120 --> 00:13:16,610
So these are the two that we're setting right.

208
00:13:17,820 --> 00:13:18,930
Wonderful.

209
00:13:19,020 --> 00:13:26,170
And so to fit it we would go for it and we need to drop the sale price columns.

210
00:13:26,210 --> 00:13:31,440
This is our ex SO sale price and access equals one.

211
00:13:31,440 --> 00:13:39,670
So we're dropping Sal Price and then we're going to pass it just the sale price column as the target.

212
00:13:39,690 --> 00:13:41,070
So this is Model not fit.

213
00:13:41,070 --> 00:13:48,530
This is ex and this is why so DFT lamp sale price.

214
00:13:48,580 --> 00:13:50,490
Let's say if it works.

215
00:13:55,060 --> 00:13:55,770
Oh no.

216
00:13:55,950 --> 00:13:57,560
We got a value error.

217
00:13:57,580 --> 00:13:58,390
What's it saying.

218
00:13:58,420 --> 00:14:01,250
Could not convert string to float low.

219
00:14:01,330 --> 00:14:10,420
You know why this is is because if we go DFA dot info all of our data is not in numeric format are int

220
00:14:10,990 --> 00:14:14,920
float int object usage band.

221
00:14:14,950 --> 00:14:15,320
Okay.

222
00:14:15,320 --> 00:14:17,020
What what type is that.

223
00:14:17,050 --> 00:14:17,910
Let's have a look.

224
00:14:17,920 --> 00:14:22,360
This is part of model driven EDTA right where our machine learning model just told us that thanks to

225
00:14:22,360 --> 00:14:27,490
the beautiful people of psychic line they've put in these errors to help us out of what's going on.

226
00:14:27,490 --> 00:14:29,930
So usage.

227
00:14:29,980 --> 00:14:31,240
No not use a warning.

228
00:14:31,230 --> 00:14:36,530
Usage band dot D type.

229
00:14:36,810 --> 00:14:37,790
What's gone on it.

230
00:14:37,980 --> 00:14:40,250
D type O object.

231
00:14:40,290 --> 00:14:46,410
Okay so maybe it's a string or something like that and the other thing is I just remembered we've got

232
00:14:46,410 --> 00:14:49,820
a whole bunch of missing values.

233
00:14:50,460 --> 00:14:57,150
So from what we know about our machine learning models which we're again modeling but we've got data

234
00:14:57,180 --> 00:15:02,040
that's not numeric and a whole bunch of data that's missing.

235
00:15:02,040 --> 00:15:05,030
So before we build a machine learning model we'll have to take care of that.

236
00:15:05,040 --> 00:15:08,500
So that's really what we'll do over the next couple of videos we'll do some model driven PDA.

237
00:15:08,790 --> 00:15:13,200
And the beautiful thing is is we just tried to run that machine learning model and it told us hey we

238
00:15:13,200 --> 00:15:16,590
can't it's not going to work because you've got non numbers in your data.

239
00:15:16,590 --> 00:15:18,030
You've got some strings in your data.

240
00:15:18,040 --> 00:15:22,200
And if we were to go again it might tell us eventually that we've got missing data.

241
00:15:22,230 --> 00:15:23,780
So that's what we need to handle first.
