In this video, we'll be implementing it and then to be used in the airline passengers time series,
so the basic outline for the script is as follows.
We're going to go through the same usual steps as we did for regular machine learning.
The first step will be to create the one step forecast.
The second step will be to create the incremental, multi-step forecast.
The third step will be to create the multi output forecast.
So these are the three steps.
Same as you've seen before.
OK, so we'll begin by importing pandas, non-pay and matplotlib as usual, the next step is to import
the relevant parts of Tenzer flow.
You'll see how each of these are used throughout this script.
I'm also going to set some random seeds so that we can get consistent results.
Of course, in the real world, you should turn this off and make sure that your code works with any
random seed.
The next step is to update cycle learn.
The next step is to import the main metric.
The next step is to download our airline passengers CSFI.
The next step is to load in our CEV using reads CSFI.
The next step is to compute the log, transform.
The next step is to split our data into train and test.
The next step is to create index arrays for both training and test.
The next step is to compute the first difference of our data.
As mentioned often in this course, there are always going to be many options to try many more than
we can go through in these videos.
So you already know why defensing is useful, but perhaps you may believe that it is still not necessary.
So if you think deep learning is powerful enough such that you don't have to difference, please give
it a try.
The next step is to create a supervised data center out of our Time series, since you've seen this
code before.
I won't explain it again.
The next step is to split our supervised dataset into training and test.
The next step is to create our neural network.
OK, so basically this is review from the previous lecture.
We start by creating an input layer which has input dimensionality t normally we call this D, but since
this is a time series, our features are actually just the time series values.
So we call it T.
The next step is to create our first hidden layer.
I've arbitrarily chosen ahead and size of 32.
I've also chosen a new activation, which is pretty standard these days.
Note that I've not added any additional hidden layers, although there is nothing stopping you from
doing so.
Recall that in the real world, choosing these values is just a matter of trial and error.
The next step is to create our final output layer, which is just a dance of output, size one.
This is because our initial model is a one step predictor.
OK, and finally we instantiate a model object passing in the input and output of our layers.
The next step is to call the compile function as mentioned, we'll use the mean squared error loss and
by default we'll choose the atom optimizer.
The next step is to call the fifth function, so we start by passing an X train and Y train, which
are the first two arguments.
The next step is to pass in the number of epochs which have set to one hundred again, choosing this
value as a matter of trial and error.
You want to make sure that your loss per iteration looks reasonable after training is complete.
The next step is to pass in the validation data, which is X test and Y test.
OK, so the next step is to plot the loss per iteration for both training and test.
As you can see, they both decrease and converge as expected, you may want to try more or less epochs
depending on what you see.
The next step is to set the first T plus one values in train reacts to false since, as you recall,
these items are not predictable.
The next step is to compute our model predictions, recall that these are for the Difference this Time
series.
Also note that for Tenzer flow, the output of the model will be N by one, since we specified that
the output has size one.
However, this can be used in the subsequent code.
Therefore, we'll call the a flattened function which will turn these into one arrays.
The next step is to store our different predictions in the data frame.
The next step is to plot the difference to predictions.
So these look pretty accurate, but remember, this is just a one step prediction.
The next step is to earn a difference, our predictions, so we'll start by shifting the log passengers
up by one.
The next step is to grab the last known train value.
The next step is to compute and store the one step forecast using the same method you've seen before.
The next step is to plot the one step forecast.
So as you can see, it looks pretty good, but again, it's just the ones that forecast.
The next step is to compute the multi-step forecast.
Note that this code is the same as before, so I won't explain it again.
The next step is to indifference the multistep predictions to get our multi-step forecast.
The next step is to plot the multi-step forecast.
So as you can see, the multistep forecast looks pretty good, in fact, just as good as the ones that
forecast.
The next step is to create our multi output supervised data set since you've seen this before.
I won't explain it again.
The next step is to split our new data center into train and test.
The next step is to create our and note that this is the same as our previous CNN, except that the
output now has size T.Y..
The next step is to compile a model same as before.
The next step is to fit our model with our new multi output data set.
The next step is to plot the loss prepack.
And it seems to be OK.
The next step is to call model predict, to get our predictions.
Note that this time we do not flatten the predictions.
So as you can see, the predictions are now of size and by 12, each row contains a 12 step forecast.
The next step is to index our predictions, so we'll do this differently for both train and test for
the train set, we'll treat them like one step predictions and simply grab the zero column.
As you recall, the time steps are redundant.
For example, if the first row has a prediction for why, one way to win, why three, the second row
will have a prediction for why two, why three and why four?
So why two and why three would be redundant predictions.
Now it's reasonable to believe that the predictions closer to the current time would be more accurate.
So we'll only use the zero with row, which represents the prediction for one time step ahead for the
test set.
We have only one sample, but each of the 12 predictions are stored along the row.
So we grabbed the zeroth row to get the 12 step forecast.
The next step is to compute the difference forecast using the same method as before.
The next step is to plot our new forecast.
So interestingly, this time, it looks like the incremental forecast was better.
The next step is to compute the map of our predictions.
So this confirms what we saw above, the incremental forecast seems to be a bit better.