So let's now take a look at some code for
LSTMs and how they can work
with the data that we've been playing with all week.
So here's the update to our code to use LSTMs.
Let's unpack it and take a look at the interesting parts.
First of all is the tf.keras.backend.clear_session,
and this clears any internal variables.
That makes it easy for us to experiment without
models impacting later versions of themselves.
After the Lambda layer that expands the dimensions for us
I've added a single LSTM layer with 32 cells.
I've also made a bidirectional to
see the impact of that on a prediction.
The output neuron will give us our prediction value.
I'm also using a learning rate of one times 10 _
minus six and that might be worth experimenting with too.
So here's the results of running this LSTM on
the synthetic data that we've
been using throughout the course.
The plateau under the big spike is still
there and are MAE is in the low sixes.
It's not bad, it's not great, but it's not bad.
The predictions look like there might be
a little bit on the low side too.
So let's edit our code to add
another LSTM to see the impact.
Now you can see the second layer
and note that we had to set
return sequences equal to true on
the first one in order for this to work.
We train on this and
now we will see the following results.
Here's the chart. Now it's tracking
much better and closer to the original data.
Maybe not keeping up with
the sharp increase but at least it's tracking close.
It also gives us a mean average error that's a lot
better and it's showing
that we're heading in the right direction.
If we edit our source to add
a third LSTM layer like this,
by adding the layer and having
the second layer return sequences is
true we can then train and run it,
and we'll get the following output.
There's really not that much of
a difference and are MAE has actually gone down.
So that's it for looking at
LSTMs and predicting our sequences.
In the next video you'll take a look at
using convolutions to see what
the impact will be on using
them for predicting time-series content.