1
00:00:11,120 --> 00:00:16,730
So in this video, we will continue looking at the notebook for human activity recognition, we just

2
00:00:16,730 --> 00:00:22,160
learned about how the data is organized so we have a decent enough understanding in order to pass it

3
00:00:22,160 --> 00:00:23,510
into the format we need.

4
00:00:24,590 --> 00:00:26,780
So let's start by defining a few constants.

5
00:00:27,350 --> 00:00:30,470
Note that you can get these values by looking at the data files.

6
00:00:31,940 --> 00:00:34,790
So we'll start with big tea, which we know is one twenty eight.

7
00:00:35,750 --> 00:00:38,660
Next, we have entraining and test, which are as follows.

8
00:00:39,110 --> 00:00:40,940
Basically you can find these by counting.

9
00:00:40,940 --> 00:00:47,930
The number of rows in any of the data files is equal to nine since we have nine parallel time series

10
00:00:48,170 --> 00:00:51,290
and K is equal to six since we have six classes.

11
00:00:56,240 --> 00:00:59,810
OK, so the next step is to define a function and call the load data.

12
00:01:00,440 --> 00:01:05,490
Again, it helps to think about what we need so that the code we write will go towards that goal.

13
00:01:06,200 --> 00:01:10,630
And of course, this just goes back to what we learned in the section about Time series basics.

14
00:01:11,120 --> 00:01:16,110
We'd like to have an X array of size and by TBD Biddy's and we'd like to have a wide array of length

15
00:01:16,110 --> 00:01:16,500
then.

16
00:01:17,420 --> 00:01:19,310
And this goes for both training and test.

17
00:01:22,440 --> 00:01:28,290
OK, so we'll start by reallocating our eggs train a next test to raise, both of which are invited.

18
00:01:31,100 --> 00:01:36,170
The next step is to instantiate a list containing the file names of each file, which contain our Time

19
00:01:36,170 --> 00:01:36,710
series.

20
00:01:37,100 --> 00:01:38,480
Note that this is for train.

21
00:01:41,670 --> 00:01:46,770
The next step is due to find a far path prefix, which is just the folder where these files are located.

22
00:01:50,070 --> 00:01:54,640
The next step is to live through each of the file names, since we use the enumerate function.

23
00:01:54,690 --> 00:01:56,340
This gives us the index as well.

24
00:01:57,180 --> 00:02:02,280
OK, so inside the loop, we begin by using pandas to load the file into the data frame.

25
00:02:02,730 --> 00:02:04,410
You should recall this code from earlier.

26
00:02:07,880 --> 00:02:14,360
The next step is to immediately convert the data frame into an empire which we call Little X. Now,

27
00:02:14,360 --> 00:02:16,720
again, it's always helpful to think about shapes.

28
00:02:17,030 --> 00:02:18,800
So what is the shape of little X?

29
00:02:19,280 --> 00:02:25,880
Well, it has nine rows and rows a time series of length, Big T, therefore, little X has the shape.

30
00:02:25,880 --> 00:02:32,330
And by T this makes sense since we have a D of these files and if we join them all together, we get

31
00:02:32,330 --> 00:02:33,330
invited.

32
00:02:34,640 --> 00:02:41,420
OK, so this means we have to index X train in the third dimension with the index little D, we assign

33
00:02:41,420 --> 00:02:46,640
this portion of X train to be a little X, OK, so hopefully this all makes sense.

34
00:02:47,120 --> 00:02:51,800
By the time this loop is over you will have all nine time series stored inside X train.

35
00:02:54,920 --> 00:03:00,890
The next step is to load in our labels again, we can use pennies for convenience and immediately convert

36
00:03:00,890 --> 00:03:02,020
it into an empire.

37
00:03:03,170 --> 00:03:08,090
Since the labels start from one, we are going to subtract one so that they all start from zero.

38
00:03:08,840 --> 00:03:14,120
We also want to flatten the labels, since using a data frame will give us to the objects of shape and

39
00:03:14,120 --> 00:03:16,180
buy one for this code.

40
00:03:16,190 --> 00:03:18,440
It's better to just have a onesie array of length n.

41
00:03:21,470 --> 00:03:27,260
OK, so the next step is to do the exact same steps, but for the test set, since this code is pretty

42
00:03:27,260 --> 00:03:29,600
much all the same, there is nothing to explain.

43
00:03:30,410 --> 00:03:34,130
Basically anywhere you previously saw train, you now see test.

44
00:03:39,630 --> 00:03:44,880
OK, so the next step is to use our function, which gives us X and Y for both training and test.

45
00:03:51,430 --> 00:03:57,370
Now, just as a sanity check, let's plot the multivariate time series of a single sample of chosen

46
00:03:57,370 --> 00:04:00,080
sample seven thousand for no particular reason.

47
00:04:00,880 --> 00:04:06,490
OK, so let's think about what the shape of this data will be since we index to an array of size and

48
00:04:06,490 --> 00:04:10,830
by TBD at some row, the result will be of shape TBD.

49
00:04:11,470 --> 00:04:16,720
So this is a single multivariate time series of length T with dimensions.

50
00:04:20,700 --> 00:04:26,220
OK, so this is a plot of all the details series at once, nothing special, but it gives you a sense

51
00:04:26,220 --> 00:04:27,840
of what the data looks like.

52
00:04:32,720 --> 00:04:38,960
OK, so the next step is to build our model, we'll begin by creating two empty lists to store inputs

53
00:04:38,960 --> 00:04:39,820
and features.

54
00:04:40,730 --> 00:04:45,350
The features are just the output of each mini neural network that will process different dimensions

55
00:04:45,500 --> 00:04:46,700
of the Time series.

56
00:04:49,890 --> 00:04:55,060
The next step is to enter a loop that goes these times inside the loop.

57
00:04:55,080 --> 00:05:01,410
We declare an input object with the shape T. So this is what we have for processing a univariate time

58
00:05:01,410 --> 00:05:01,960
series.

59
00:05:02,670 --> 00:05:06,870
Basically, we're just processing a univariate time series D Times.

60
00:05:08,220 --> 00:05:10,330
The next step is to create some dense layers.

61
00:05:10,920 --> 00:05:16,410
Note that I've chosen the number of hidden units in the number of hidden layers arbitrarily, so please

62
00:05:16,410 --> 00:05:18,150
feel free to try different things.

63
00:05:19,470 --> 00:05:20,310
At this point.

64
00:05:20,340 --> 00:05:24,410
The final X variable refers to the output of this many neural network.

65
00:05:24,810 --> 00:05:30,120
So we append AI to the list of inputs and we appendix to the list of features.

66
00:05:32,430 --> 00:05:38,610
OK, so once that loop is done, the features list will contain the outputs of all the mini neural networks.

67
00:05:39,180 --> 00:05:43,260
The next step is to create the concatenate layer, which joins other features together.

68
00:05:44,160 --> 00:05:50,220
So since you have nine feature vectors each of size 16, the result will be a big feature vector of

69
00:05:50,220 --> 00:05:51,980
length, nine times 16.

70
00:05:53,160 --> 00:05:58,630
Once we've done our concatenation, we have one final dense layer with K outputs as usual.

71
00:05:59,610 --> 00:06:04,800
The last step is to create our model objects passing in the list of inputs and the output x.

72
00:06:11,140 --> 00:06:16,270
OK, so when you have a complicated model like this, it's useful to create a picture of your model,

73
00:06:16,720 --> 00:06:20,170
the tensor flow plot model function can be used to do this.

74
00:06:24,940 --> 00:06:30,490
So as you can see, our model is basically nine parallel mini neural networks, all taking in a different

75
00:06:30,490 --> 00:06:32,680
part of the multivariate time series.

76
00:06:33,130 --> 00:06:38,470
After the data goes through these many neural networks, they are combined together into a single feature

77
00:06:38,470 --> 00:06:38,950
vector.

78
00:06:39,640 --> 00:06:43,060
That single feature vector then goes through one final dense layer.

79
00:06:43,750 --> 00:06:46,440
OK, so this is a multi tailed neural network.

80
00:06:49,430 --> 00:06:51,230
The next step is to create a checkpoint.

81
00:06:51,770 --> 00:06:57,210
This will be used to save the best model according to some validation metric during the training process.

82
00:06:57,770 --> 00:06:59,440
So we have three arguments.

83
00:06:59,840 --> 00:07:05,570
The first argument is the file name to save the best model to the second argument is which metric to

84
00:07:05,570 --> 00:07:06,170
monitor.

85
00:07:06,680 --> 00:07:11,350
You could choose the laws here, but since we are paying attention to accuracy, that's what I've chosen.

86
00:07:12,410 --> 00:07:16,880
The third argument is used so that it doesn't save every model, but only the best model.

87
00:07:20,350 --> 00:07:25,600
OK, so the next step is to call the compile function, this is similar to what we've seen before,

88
00:07:25,630 --> 00:07:28,330
except for two things for the loss.

89
00:07:28,330 --> 00:07:34,220
Instead of specifying a string, we specify an object of type, sparse, categorical cross entropy.

90
00:07:34,720 --> 00:07:39,010
We're going to set from sequel to true since our model outputs Logits.

91
00:07:39,400 --> 00:07:44,290
If we use the default value of false, you would have to end your neural network with a softmax.

92
00:07:45,010 --> 00:07:49,070
You don't have to worry about why we do this, but the reason is for numerical stability.

93
00:07:49,510 --> 00:07:53,560
As always, you can check extra reading text for more information.

94
00:07:54,490 --> 00:07:58,630
The next thing to notice is that we've passed in accuracy as the metric to track.

95
00:07:59,320 --> 00:08:02,230
So when we're doing forecasting, this is not really needed.

96
00:08:02,230 --> 00:08:08,290
Since the mean squared error is both the loss and the metric we to track for this problem is different

97
00:08:08,290 --> 00:08:11,260
because the loss and accuracy are two separate things.

98
00:08:14,710 --> 00:08:19,240
The next step is to convert our data into a format that will work with our neural network.

99
00:08:19,780 --> 00:08:23,310
As you recall, our model is defined to take in a list of inputs.

100
00:08:23,650 --> 00:08:27,490
It does not accept an array of size N by T by D directly.

101
00:08:28,270 --> 00:08:32,950
That would be the case for CNN's and Arnon's, but it's not the case for a special, multi tailored

102
00:08:32,950 --> 00:08:33,510
model.

103
00:08:34,210 --> 00:08:39,100
So the function we built earlier is more general in that IT future proves us for the later sections

104
00:08:39,100 --> 00:08:40,610
on CNN's in Arnon's.

105
00:08:41,260 --> 00:08:46,360
So basically we're going to live through each dimension of our Time series and separate each dimension

106
00:08:46,540 --> 00:08:49,480
so that we get a list of univariate time series.

107
00:08:53,880 --> 00:08:59,460
The next step is to call our fifth function, so the arguments to this are the same as we've seen before,

108
00:08:59,490 --> 00:09:03,210
except we are now passing in a list of inputs where X would normally go.

109
00:09:03,360 --> 00:09:04,770
And we have our checkpoint's.

110
00:09:13,540 --> 00:09:15,730
The next step is to plot our lansberry prepack.

111
00:09:20,850 --> 00:09:22,950
OK, so here is our Lansberry Park.

112
00:09:23,340 --> 00:09:26,430
Notice that the train loss is much better than the loss.

113
00:09:33,570 --> 00:09:35,470
And this is our accuracy report.

114
00:09:36,030 --> 00:09:38,160
So we see the same pattern as the Los.

115
00:09:42,100 --> 00:09:47,830
The next step is to load back our best model by calling the load model function, notice that we pass

116
00:09:47,830 --> 00:09:50,530
in the filename that matches with our checkpoint.

117
00:09:53,390 --> 00:09:57,020
The next step is to call the Predix function to get our test predictions.

118
00:10:00,380 --> 00:10:02,780
The next step is to check the accuracy of our model.

119
00:10:03,680 --> 00:10:05,580
OK, so what's happening here?

120
00:10:06,260 --> 00:10:11,030
So as you recall, test is an endemic matrix of probabilities.

121
00:10:11,630 --> 00:10:15,720
In order to convert these to labels, we need to take the Amax on each row.

122
00:10:16,370 --> 00:10:19,910
The results of this will be a one degree of predictive labels.

123
00:10:20,850 --> 00:10:26,330
OK, so once we have the predicted labels, we can use the equals equals operator to compare them to

124
00:10:26,330 --> 00:10:27,180
Y test.

125
00:10:27,680 --> 00:10:33,200
So this does an element wise comparison and the result will be an array of booleans either true if we

126
00:10:33,200 --> 00:10:34,520
are correct and false.

127
00:10:34,520 --> 00:10:41,460
Otherwise, as you recall in Python, a true is treated like one and false is treated like zero.

128
00:10:41,810 --> 00:10:46,910
Therefore, when we take the mean of this array, we get the accuracy, which is ninety two point six

129
00:10:46,910 --> 00:10:47,600
percent.

130
00:10:48,440 --> 00:10:51,020
OK, so this seems like a pretty decent result.

131
00:10:51,290 --> 00:10:53,990
But then again, we don't have any point of comparison.
