OK, so for this code, the main idea is not to focus on every line, but to focus on what is different.
You'll notice that most of this is the same as what we had before.
So when we build our supervised data set, notice that we now use the difference in log passengers,
also notice that we start from index one instead of taking the full array.
This is because due to taking the first difference, the first value is zero.
The next thing to notice is that R squared is much lower than before with a stationary time series.
We can't simply predicts the previous value, which you've seen leads to a higher squared in particular
cases.
The next thing to notice is that for the train index, we now said the first big plus one values to
false.
Previously this was just big T.
The next step is to compute the previous values, which we need to d difference our predictions for
one step predictions, we can do this simply by shifting the log passengers up by one.
For multistep predictions, we have to keep in mind that we only know the values from the train set,
so we take the last value from the train set and we call that last train.
OK, so let's see how to do the One-Step forecast for the train set, we take the shifted values in
the train and add them to our predictions.
You should recognize this from the equations we saw earlier for the test set.
We do the same thing.
Notice that this only applies to the ones that forecast.
So you can see that the results look pretty good, much better than before, we now do not have a problem
reaching the peak.
The next step is to look at the incremental multistep forecast.
Now, the loop to make the incremental predictions is the same.
This gives us our deltas.
The part that's different is what we do with these deltas.
So this time it's a multi-step forecast, so the last known value comes from the train.
So we take the last train value and add it to the cumulative some of the deltas.
So we see that the multistep prediction is also pretty good.
OK, so again, most of this stuff like the code to build the data set is the same as before.
Notice again that the R-squared is lower because we're trying to predict a time series where there isn't
a lot of correlation in the values.
OK, so again, the forecast is the last train value, plus the cumulative some of the predictions.
So we again see that the forecast is pretty good, but it's hard to tell from this plot.
Which one is best?
So when we look at the map, we see that the multipotent forecast achieves the best value.
OK, so the next part is, again, to test different models, so this function follows exactly the same
pattern.
The only difference, again, is that we use our new calculations to difference the predictions.
OK, so let's try the support vector machine.
So the support vector machine doesn't do too well.
The next step is to try the random forest.
So this does pretty well, it seems to be on par with linear regression.
The next step is to look at the multi output forecast.
So, again, there's nothing really different about this function.
Now, recall that the support vector machine does not support having multiple outputs.
However, this does not stop us from simply creating our own SVM that can handle multiple outputs.
It simply means we're going to create a separate support vector machine, one for each time step of
the forecast.
So here you can see I've created my own class called SVR wrapper in the constructor, we take in the
forecast horizon and generic keyword arguments, which will be passed on to the SVR constructor inside
the constructor.
We simply save the forecast horizon and we instantiate multiple SVR objects, one for each time step
inside the fit function.
We simply call fit for each SVR, for each column of the target matrix.
Inside the predicts function, we simply call predict for each SVR and then stack the result.
Notice that we use each stack.
Since each output is an end length vector, the result will be a new array of size n by the forecast
horizon.
OK, so in the next block, we're going to test our custom SVR rapper.
Notice how it still does not perform too well.
It seems like this is simply not a good model for this Time series, but note that you can still tune
the hyper parameters.
OK, so we see that the random forest does very well notice how much better it performs when we do different
saying.