1
00:00:11,010 --> 00:00:17,160
In this video, we will be looking at how to implement CNN's and TensorFlow for airline passengers.

2
00:00:17,370 --> 00:00:21,750
The script will follow the same pattern as the previous scripts with three steps.

3
00:00:22,020 --> 00:00:27,000
We'll start with the one step forecast, followed by an incremental multi step forecast.

4
00:00:27,270 --> 00:00:31,680
The third option will try is the multi output multi step forecast.

5
00:00:32,610 --> 00:00:37,290
Please note that at this point you have the data and you know exactly the syntax we'll be using.

6
00:00:37,290 --> 00:00:42,270
So if you'd like to treat this as an exercise using what you've learned, please stop this video and

7
00:00:42,270 --> 00:00:43,470
try this yourself.

8
00:00:43,500 --> 00:00:48,670
Otherwise, let's continue now because most of this script is the same as before.

9
00:00:48,690 --> 00:00:51,050
We will only look at the relevant parts.

10
00:00:51,060 --> 00:00:53,010
So let's start with the imports.

11
00:00:53,400 --> 00:00:58,740
You can see that there are a few new layers here, such as convoy and max pooling one rd and global

12
00:00:58,740 --> 00:01:00,090
max pooling one DX.

13
00:01:00,690 --> 00:01:05,640
The next step is to perform the rest of our imports and load in our data, which you've already seen.

14
00:01:15,030 --> 00:01:19,430
Note that again, we're using the different time series as before.

15
00:01:19,440 --> 00:01:23,400
If you believe that this should work without different saying, you are welcome to try.

16
00:01:30,040 --> 00:01:35,980
Also note that because the input data must have the shape end by t by DX, we now add an extra superfluous

17
00:01:35,980 --> 00:01:38,140
dimension at the end of X.

18
00:01:38,380 --> 00:01:42,250
Previously it was end by t, now it's end by T by one.

19
00:01:47,550 --> 00:01:49,770
The next step is to build our CNN.

20
00:01:49,980 --> 00:01:55,200
Notice that the shape of our input has changed since our time series has one dimension.

21
00:01:55,200 --> 00:01:57,630
Its correct shape is t by one.

22
00:01:58,200 --> 00:02:00,810
The next step is to declare a conjoined layer.

23
00:02:01,020 --> 00:02:04,470
This has 16 feature maps with a kernel size of three.

24
00:02:04,800 --> 00:02:08,460
As per the usual pattern, we follow this with max pooling.

25
00:02:10,110 --> 00:02:12,990
The next step is to add another kind of 1D layer.

26
00:02:13,020 --> 00:02:16,680
This has 32 feature maps with a kernel size of three.

27
00:02:17,190 --> 00:02:21,510
Since this is our last convolution layer, we follow it with global max pooling.

28
00:02:21,630 --> 00:02:25,860
Alternatively, you could use global average pooling or a simple flatten.

29
00:02:27,660 --> 00:02:33,360
The next step is to add our final dense layer with one output since we are doing one step predictions.

30
00:02:38,550 --> 00:02:41,970
The next step is to call a very useful function called summary.

31
00:02:46,490 --> 00:02:51,500
So what this does is it lifts each layer of your model and tells you the output shape of the data at

32
00:02:51,500 --> 00:02:54,890
each step, along with the number of parameters of the layer.

33
00:02:55,790 --> 00:03:00,800
This will help you understand how your data is transformed as it goes through the neural network.

34
00:03:02,090 --> 00:03:08,000
So you can see that the model starts out as ten by one, meaning a length ten time series with one dimension.

35
00:03:08,360 --> 00:03:12,770
After doing convolution, it has a length of eight and 16 feature maps.

36
00:03:13,670 --> 00:03:19,580
Note that the time dimension is smaller because by default TensorFlow uses valid mode convolution.

37
00:03:20,900 --> 00:03:26,240
Since our max pool has size two, the data shrinks by half, so it goes from 8 to 4.

38
00:03:26,750 --> 00:03:30,500
After one more valid mode convolution it becomes size two.

39
00:03:30,650 --> 00:03:33,440
We also specified 32 feature maps.

40
00:03:34,160 --> 00:03:38,510
At that point we use global max pooling and the time dimension disappears.

41
00:03:38,660 --> 00:03:41,870
So we now have a feature vector of size 32.

42
00:03:42,860 --> 00:03:44,870
This can be passed through regular dense layers.

43
00:03:44,870 --> 00:03:48,650
And so after our final linear layer, our output has size one.

44
00:03:53,010 --> 00:03:56,370
So the next step is to call, compile and fit as usual.

45
00:04:03,800 --> 00:04:06,290
The next step is to look at the lost per epoch.

46
00:04:10,710 --> 00:04:12,660
So the lost epoch looks fine.

47
00:04:15,570 --> 00:04:17,790
The next step is to plot our predictions.

48
00:04:23,790 --> 00:04:25,140
Okay, so these are the difference.

49
00:04:25,290 --> 00:04:26,850
One step predictions.

50
00:04:30,730 --> 00:04:33,070
The next step is to undo the different thing.

51
00:04:38,360 --> 00:04:41,540
So this is the one step under forecast.

52
00:04:41,720 --> 00:04:46,070
This looks good, but we know what really matters is the multi step forecast.

53
00:04:52,540 --> 00:04:55,060
So this is the multi step forecast.

54
00:04:55,090 --> 00:04:58,660
It seems to look just as good as the one step forecast.

55
00:05:01,790 --> 00:05:05,300
The next step will be to compute the multi output forecast.

56
00:05:12,210 --> 00:05:15,720
So this is our CNN for the multi output forecast.

57
00:05:15,870 --> 00:05:20,820
Notice that this has the same architecture as before, except with t outputs.

58
00:05:25,420 --> 00:05:28,810
So the next step is to call, compile and fit as usual.

59
00:05:35,050 --> 00:05:37,540
The next step is to look at the loss per epoch.

60
00:05:41,150 --> 00:05:43,190
So the lost per epoch looks fine.

61
00:05:45,730 --> 00:05:48,730
The next step will be to plot our new model predictions.

62
00:05:54,590 --> 00:05:57,560
Okay, so the multi output predictions look fine.

63
00:05:59,920 --> 00:06:01,720
The next step will be to undo the difference.

64
00:06:01,720 --> 00:06:02,350
Saying.

65
00:06:09,450 --> 00:06:12,840
So these are the undifferentiated multi outward predictions.

66
00:06:12,930 --> 00:06:15,900
Note that it's difficult to tell which version is best.

67
00:06:19,480 --> 00:06:21,340
The next step is to check the map.

68
00:06:24,850 --> 00:06:28,570
So as you can see, the map looks pretty good in both cases.

69
00:06:28,690 --> 00:06:33,970
As always, you might want to try to undo the logging and try different metric so that you can compare

70
00:06:33,970 --> 00:06:36,190
this model with the other models we've seen.

71
00:06:36,820 --> 00:06:40,000
Please try that as an exercise and I'll see you in the next lecture.
