In this video, we will continue looking at our Varma Notebook for predicting temperatures.
To recap, what we've done so far is loaded in our data, which wasn't in the T by D format we expected.
So we did some work to convert it into that format and we plotted the data to see what it looks like.
The next step is to split our data into train and test.
So I've chosen n test equals 12, which represents one year.
The next step is to scale our data.
As you recall, the temperatures are not on the same scale and they're also pretty large Fahrenheit
values.
So you can see that I've used a fit transform on the train set and transform on the test at the new
scale.
Two columns are given a new name, which is the old name pre with scaled.
The next step is to scale the other column.
The next step is to create a train idea and test out X, which you've seen before.
As you recall, we use these to index the original data frame for both the train and test sets.
The next step is to also put the scale data back into the original data frame.
As you recall, train and test are just copies.
The next step is to plot the scaled columns.
So as you can see, the two time series are now on the same scale.
The next step is to plot the arc of the first column.
As you recall, we can use these to guide our choice for the number of legs in our model.
Notice how the ACF has a strong seasonal pattern due to the fact that the Time series itself has a strong
seasonal pattern.
The next step is to plot the ICF.
So we see a similar pattern, except that the lags closer to zero are more significant.
The next step is to plot the ACF for the second column.
So again, there is a strong seasonal pattern.
The next step is to plot the passage of the second column.
So again, we see a similar pattern.
The next step is to create a var max object and fit it to the Time series.
Note that because this is going to take some time, I've used datetime to measure the duration.
Also notice that I've picked P equals ten and Q equals ten for no particular reason.
Feel free to try other values if you like.
Okay.
So you'll see that when you use a queue other than zero, you'll get this estimation warning saying
that the estimation of parameters has ID issues.
This is because the solution is not unique.
What you'll also notice is that due to the training methods used behind the scenes, fitting a Varma
model takes much longer than a pure VAR model.
In any case, we'll continue using Varma for now.
So make note of how long this took to train.
The next step is to call the get forecast function to get the forecast for pn test time steps.
The next step is to demonstrate that the results objects.
We got back from fitting.
The model already contains the in sample predictions in an attribute called fitted values.
As you can see, it returns a series.
The next step is to store the predictions in the original joint part DataFrame.
So we use train for the end sample predictions, assigning it to be the fitted values we use.
Test X for the out of sample predictions, assigning it to be the predicted mean of the forecast.
The next step is to plot our predictions along with the original TIME series.
Note that we only plot the last 100 values to keep the plot a reasonable size.
So as you can see, both the train and test predictions look pretty good.
The next step is to perform all the same steps for the other city.
So again, we store the sample and out of sample predictions.
Note that this uses the same objects we had before, since they store the predictions for both cities.
The next step is to plot our predictions.
Okay.
So as you can see, our predictions for the second city look pretty similar.
The next step is to check the R squared of our model.
Basically, we can just index the data frame where we stored the predictions.
Okay.
So the r squared for oakland looks pretty good.
The next step is to check the R squared for Stockholm.
So again, the R squared looks pretty good.
Now, of course, how good these predictions really are doesn't depend on these values in isolation.
Instead, what we should really do is compare to a baseline.
So the reason I chose to use Varma first is because after years of getting to know my students online,
I believe this is what they would want to try.
Of course, we've already seen a few disadvantages of Varma.
One issue is that Varma processes are generally not identifiable.
Another problem is that they take longer to train.
So in the coming lecture, we'll explore alternative options and also compare their performance.