In the previous video, you saw how to prepare
a time series for machine learning by windowing the data.
You saw the code to create a very simple dataset,
and then you learned how you can prepare
that dataset as features and labels or x's and y's.
In this video, you'll go through
a screencast of a notebook
that contains all of that code.
Okay. To start, you'll need to
have TensorFlow 2.0 installed.
To check your version, run this code block.
The output should read 2.0.0 something.
In this case, I'm running a nightly build
hence the dev code at the end.
If you need 2.0, you can install with code like this.
The tf-nightly-2.0-preview is the dev version
I just mentioned or alternatively,
you can install with pip install tensorflow like this.
The version might be different than
b1 because at the time I recorded this,
TensorFlow had been released as beta 1.
Check tensorflow.org for the latest instructions
for installing the production bits.
Once you've installed TensorFlow,
you can run this code.
First, we'll create a simple dataset,
and it's just a simple range containing
10 elements from zero to nine.
We'll print each one out on its own line as you can see.
Next, we'll window the data into chunks of five items,
shifting by one each time.
We'll see that this gives us
the output of the first five items,
and then the second five items,
and then the third five items, etc.
At the end of the dataset,
when there isn't enough data to give us five items,
you'll see shorter lines.
To just get chunks of five records,
we'll set drop_reminder to true.
When we run it, we'll see that our data looks like this.
We've got even sets that are the same size.
TensorFlow likes its data to be in numpy format.
So we can convert it easily by calling
the dot numpy method and when we print it,
we can see it's now listed in square brackets.
Next up is to split into
x's and y's or features and labels.
We'll take the last column as the label,
and we'll split using a lambda.
We'll split the data into column minus one,
which is all of the columns except the last one,
and minus one column which is the last one only.
Now we can see that we have a set of
four items and a single item.
Remember that the minus one column
denotes the last value in the list,
and column minus one
denotes everything about the last value.
As such, we can see zero, one, two,
three and one, two, three,
four before the split just for example.
Next of course, is to shuffle the data.
This is achieved with the shuffle method.
This helps us to rearrange the data so as not to
accidentally introduce a sequence bias.
Multiple runs will show the data in
different arrangements because it gets shuffled randomly.
Finally, comes batching.
By setting a batch size of two,
our data gets batched into two x's and two y's at a time.
For example, as we saw earlier,
if x is zero, one, two, three,
we can see that the corresponding y
is four or if x is five,
six, seven, eight, then our y is nine.
So that's the workbook with the code that
splits a data series into windows.
Try it out for yourself,
and once you're familiar with what it does,
proceed to the next video.
There you'll move to the seasonal dataset
that you've been using two dates,
and with this windowing technique,
you'll see how to set up x's and y's that can be fed into
a neural network to see how
it performs with predicting values.