Welcome back.
In the last video we saw what we're going
to cover in brief.
Now let's have a look at time series
inputs and outputs.
You might be going, Daniel, we're five
videos into this module, we haven't written any code yet.
And I know, I know, you are 100 % correct.
However, I did say that we're covering a
fair bit of ground on this one.
So I want to set the stage.
Don't worry, we're going to write lots of code, just we'll get there in a second.
So let's have a look at the inputs and outputs of our forecasting problem.
Might be slightly different for a classification problem, but I will let
you research that yourself.
If we have the question, what will the
price of Bitcoin be tomorrow?
That is our question.
Now, what is our output?
Our output is going to be something like this.
I'm just making up the numbers here, but it's a forecasting problem.
So the output is going to be continuous.
In other words, a number.
For a classification problem, the output is usually discrete, which is a label.
So this is our model.
We have an input, pass it to BitPredict,
and we have some sort of actual output of what the price would be if this graph
went to the next day.
So what do we do?
Well, we need some way to numerically encode our time series data.
Now, the good thing is about time series data is that it's often already numerical.
Why?
Because our machine learning algorithms
love numbers.
We saw in previous modules that they
can't deal with things like pictures as they are, just like we look at them.
They need pictures in numbers.
Same with text.
But in the case of our historical price of Bitcoin, what do we have?
Well, we have different prices over different days, so it's already numerical.
Of course, this won't always be the case, but quite often time series is some
number representing some value over time.
So the good thing is it could already be
in a numerical encoding.
We're going to see later on how we format
this data to be passed to a machine learning model, but just keep this in mind.
This is a brief overview of the inputs and outputs.
And then what happens is the output here.
Well, I've got three different outputs.
Why is that?
Well, I've got three different inputs here.
So we're going to see this later on, but I just want to give you a little heads up
of what's to come.
We're going to format our time series
data because right now this is just a line.
And if we want to predict the actual
output, we need some way to train our model to figure out, say, this is the
next day of Bitcoin because it's one number.
This is the next day of Bitcoin.
We need to format our data in some way that our model takes in, say, a week's
worth of Bitcoin data.
I mean, there's only three prices here,
but just say this is a week's worth of data and then outputs the next prediction
based on the previous week of data.
And then same again, next day, week, next day.
And now for this, we would pass this last little week here, which may be this
section here, and then it would be the actual output.
So we're going to see that later on.
That's in Windows and Horizons, which is
turning a time series problem into a supervised learning problem.
But this is just a high level overview.
So I've got our predicted output, which
of course comes from looking at lots of actual outputs.
So high level overview.
Now let's translate this into BitPredict terms.
BitPredict input and output shapes.
Very important in machine learning problems.
Input and outputs as well as input and output shapes.
Majority of the errors I get for machine learning problems is tensor shapes.
And I think we've probably written enough models together now that you know the
pain I feel with input and output shapes.
So let's get specific here.
We've got a whole bunch of graphics.
We're going to talk through this.
We've got a window for one week.
We're going to become very familiar with
that term over the course of this module.
The window is the amount of data you put
into a model for a time series, very often called a window.
We'll see how to create that later on, but just say we're passing our model one
week of Bitcoin data to predict the next day, which is, if we want to predict in
the future for a time series model, it's often called the horizon.
In other words, the horizon you're predicting towards.
So in our case, we might put in one week of data to predict the next day.
And again, these values, we're going to see them later on because windows are changeable.
You might put in one month to predict the next day.
You might put in one year to predict the next month.
So you can alter these values.
But this is the main premise.
We have some sort of historical data of Bitcoin to predict the next day.
We've got our model here.
Now, if we jump down here, what are the shapes?
Well, we have batch size.
We've seen that before.
We're very familiar with batch size.
32 is a very common batch size, but
you'll often see in time series data that the batch size gets increased rather dramatically.
So 32, because our data is all numerical, and we don't usually have as much data in
a time series problem than we do for other deep learning problems.
We'll see this firsthand once we get into the code.
So we might increase 32 to something like 128 or even over a thousand.
And then we have seven here.
Why is that?
Well, we've got the window size.
So remember, how much historical data are
we using to try and predict the future?
That's the window size shape here.
Now, if this was we were using the last month, so 30 samples to predict the next
day, what would our window size be?
Well, it would be 30.
Well, if the month had 30 days, I mean, you could be using February, that's 28
days, but we'll keep it 30 to keep things simple.
Same thing with the output shape.
What might the horizon shape be if we're predicting the next day?
I mean, you can see it right here.
It's the shape is one.
But what if we were trying to predict the next week of prices?
The shape would be seven.
So input and output shape, very important
for machine learning algorithms.
But what do we already know?
Let's dive back to our philosophical endeavors of time series prediction.
What do we already know?
If we're predicting the next day, how
much chance or how good is that prediction going to be compared to if we
were predicting the next week?
Remind yourself of predicting the weather.
If you look outside, which is a short forecast, if you want to predict the
weather for the next hour, that forecast is probably going to be pretty reliable
if you just look out your window.
So that's similar to predicting the next
day of Bitcoin.
But if we predict the weather for one
week's time by just looking at our window, is that forecast going to be
quite reliable?
So keep that in mind.
Say, for example, if we predict the next week of Bitcoin data, is our seventh day
forecast going to be as reliable as the next day forecast?
So we'll see this in action later on.
But let's do a little bit more of an
overview of the input and output shapes before we move on.
So just keep this in mind.
Window is your input to a time series model.
Horizon is the output of a time series model or a forecast.
What type of problem have we seen before, especially in the natural language
processing section, that this problem could be related to?
And I've kind of already give it away.
It's a sequence problem, also called SEC2SEC.
So let me take a little step aside.
In machine learning, you're going to come
across this a lot.
And I hope I've sort of given this across
in previous videos, but if not, I'm going to state it explicitly.
Machine learning is all about framing the particular problem that you have in a
machine learning type of problem.
So in our case, sequence problem is a
very common machine learning problem.
We have, if we're trying to predict the
price for the next day, what, using the last week worth of data, what does our
problem look like?
It looks like a many to one problem.
And this is from, we've seen this in a previous video, but this is from a blog
post by Andrej Karpathy, very good blog post.
But we have many historical points of
Bitcoin, in other words, the last week worth of prices, and we're trying to
predict the next day.
So it's many to one.
But if we had the last month and we're trying to predict the next week, we could
frame it as many to many.
And again, let's get specific to bit
predict and how it looks like a sec to sec problem.
Sec to sec is short for sequence problems, sequence to sequence.
We have an input.
So this is the last historical data of
Bitcoin for the last week, window size equals seven.
We'll see what window means in a second.
We pass it in, we've got many inputs and
our output horizon is one.
So it's this price.
So many inputs to one output, same thing.
If we had same input window size equals
seven, let's pass it into a many to many model.
The output is going to be three values.
We're trying to predict say the next three days.
So the horizon equals three, window size equals seven, horizon equals three.
And so keep these things in mind.
I've bombarded you with information here.
But as I said, we're going to have lots of hands -on practice doing this,
especially formatting our data to represent it in windows and horizons.
With all of this being said, it's time to try and predict the price of Bitcoin.
And I put the word try in there on purpose.
There's a little bit of a spoiler of what
we're going to cover.
Let's bring bit predict to life.
I'll see you in Google Colab.