In this video, we will be looking at how to implement CNN's and TensorFlow for airline passengers.
The script will follow the same pattern as the previous scripts with three steps.
We'll start with the one step forecast, followed by an incremental multi step forecast.
The third option will try is the multi output multi step forecast.
Please note that at this point you have the data and you know exactly the syntax we'll be using.
So if you'd like to treat this as an exercise using what you've learned, please stop this video and
try this yourself.
Otherwise, let's continue now because most of this script is the same as before.
We will only look at the relevant parts.
So let's start with the imports.
You can see that there are a few new layers here, such as convoy and max pooling one rd and global
max pooling one DX.
The next step is to perform the rest of our imports and load in our data, which you've already seen.
Note that again, we're using the different time series as before.
If you believe that this should work without different saying, you are welcome to try.
Also note that because the input data must have the shape end by t by DX, we now add an extra superfluous
dimension at the end of X.
Previously it was end by t, now it's end by T by one.
The next step is to build our CNN.
Notice that the shape of our input has changed since our time series has one dimension.
Its correct shape is t by one.
The next step is to declare a conjoined layer.
This has 16 feature maps with a kernel size of three.
As per the usual pattern, we follow this with max pooling.
The next step is to add another kind of 1D layer.
This has 32 feature maps with a kernel size of three.
Since this is our last convolution layer, we follow it with global max pooling.
Alternatively, you could use global average pooling or a simple flatten.
The next step is to add our final dense layer with one output since we are doing one step predictions.
The next step is to call a very useful function called summary.
So what this does is it lifts each layer of your model and tells you the output shape of the data at
each step, along with the number of parameters of the layer.
This will help you understand how your data is transformed as it goes through the neural network.
So you can see that the model starts out as ten by one, meaning a length ten time series with one dimension.
After doing convolution, it has a length of eight and 16 feature maps.
Note that the time dimension is smaller because by default TensorFlow uses valid mode convolution.
Since our max pool has size two, the data shrinks by half, so it goes from 8 to 4.
After one more valid mode convolution it becomes size two.
We also specified 32 feature maps.
At that point we use global max pooling and the time dimension disappears.
So we now have a feature vector of size 32.
This can be passed through regular dense layers.
And so after our final linear layer, our output has size one.
So the next step is to call, compile and fit as usual.
The next step is to look at the lost per epoch.
So the lost epoch looks fine.
The next step is to plot our predictions.
Okay, so these are the difference.
One step predictions.
The next step is to undo the different thing.
So this is the one step under forecast.
This looks good, but we know what really matters is the multi step forecast.
So this is the multi step forecast.
It seems to look just as good as the one step forecast.
The next step will be to compute the multi output forecast.
So this is our CNN for the multi output forecast.
Notice that this has the same architecture as before, except with t outputs.
So the next step is to call, compile and fit as usual.
The next step is to look at the loss per epoch.
So the lost per epoch looks fine.
The next step will be to plot our new model predictions.
Okay, so the multi output predictions look fine.
The next step will be to undo the difference.
Saying.
So these are the undifferentiated multi outward predictions.
Note that it's difficult to tell which version is best.
The next step is to check the map.
So as you can see, the map looks pretty good in both cases.
As always, you might want to try to undo the logging and try different metric so that you can compare
this model with the other models we've seen.
Please try that as an exercise and I'll see you in the next lecture.