In this lecture, we are going to apply Holtze linear trend model in code.
This lecture is going to walk you through a prepared CoLab notebook, although a very good exercise,
which I always recommend, is once you know how this is done, to try and recreate it yourself with
as few references as possible.
As always, you can check the lectures, how to code by yourself and how to practice for a more in-depth
discussion.
If there's anything in this lecture you didn't understand or you think I missed a step or didn't explain
why we were doing something, please use the Q&A to inquire.
As usual, you can look at the title of the notebook to determine what notebook we are currently looking
at.
So first, we are going to import the whole class from stat's models.
Next, we're going to instantiate a whole to object passing in our data frame.
Next, we're going to call the fit function to fit our model.
As you know, this returns a results object next.
We're going to assign the fitted values to the whole column in our data frame.
Next, we're going to plot the whole column along with the original Time series.
As you can see, this is similar to the previous model where all it does is seem to track the previous
value.
In the next block, I'm going to again remind you what not to do, which is to shift the fitted values
backwards so that they look like they match up perfectly.
It may seem tempting, but remember, you have to be consistent.
So if later we see a model that actually does fit nicely, you still have to shift it backwards and
it's going to look very strange.
The next step is to use our train to split again so we can do a real forecast, so let's create a new
holds object and pass in the train set.
Then we call a fit function with no arguments.
Next, we assign the fitted values to our data frame for the rows corresponding to the train set.
Next, we call forecast for test time steps, and we assign the result to our data frame for the rows
corresponding to the test set.
Now, when we plot the whole column, along with the original Time series, we can see both the sample
predictions along with the out of sample forecast.
As expected, we get a straight line at trending upwards, which is exactly what the whole linear trend
model should it do in this scenario.