1
00:00:11,080 --> 00:00:15,360
In this lecture, we are going to apply Holtze linear trend model in code.

2
00:00:16,350 --> 00:00:21,570
This lecture is going to walk you through a prepared CoLab notebook, although a very good exercise,

3
00:00:21,570 --> 00:00:27,000
which I always recommend, is once you know how this is done, to try and recreate it yourself with

4
00:00:27,000 --> 00:00:28,810
as few references as possible.

5
00:00:29,340 --> 00:00:35,010
As always, you can check the lectures, how to code by yourself and how to practice for a more in-depth

6
00:00:35,010 --> 00:00:35,790
discussion.

7
00:00:36,270 --> 00:00:41,610
If there's anything in this lecture you didn't understand or you think I missed a step or didn't explain

8
00:00:41,610 --> 00:00:44,840
why we were doing something, please use the Q&amp;A to inquire.

9
00:00:45,450 --> 00:00:50,460
As usual, you can look at the title of the notebook to determine what notebook we are currently looking

10
00:00:50,460 --> 00:00:50,770
at.

11
00:00:52,200 --> 00:00:56,010
So first, we are going to import the whole class from stat's models.

12
00:00:58,740 --> 00:01:03,150
Next, we're going to instantiate a whole to object passing in our data frame.

13
00:01:05,760 --> 00:01:08,820
Next, we're going to call the fit function to fit our model.

14
00:01:11,230 --> 00:01:15,510
As you know, this returns a results object next.

15
00:01:15,820 --> 00:01:19,830
We're going to assign the fitted values to the whole column in our data frame.

16
00:01:25,020 --> 00:01:29,100
Next, we're going to plot the whole column along with the original Time series.

17
00:01:32,810 --> 00:01:38,420
As you can see, this is similar to the previous model where all it does is seem to track the previous

18
00:01:38,420 --> 00:01:38,990
value.

19
00:01:43,560 --> 00:01:49,140
In the next block, I'm going to again remind you what not to do, which is to shift the fitted values

20
00:01:49,140 --> 00:01:52,200
backwards so that they look like they match up perfectly.

21
00:01:56,350 --> 00:01:59,750
It may seem tempting, but remember, you have to be consistent.

22
00:02:00,040 --> 00:02:05,590
So if later we see a model that actually does fit nicely, you still have to shift it backwards and

23
00:02:05,590 --> 00:02:07,560
it's going to look very strange.

24
00:02:12,540 --> 00:02:18,660
The next step is to use our train to split again so we can do a real forecast, so let's create a new

25
00:02:18,660 --> 00:02:21,000
holds object and pass in the train set.

26
00:02:21,750 --> 00:02:24,270
Then we call a fit function with no arguments.

27
00:02:24,900 --> 00:02:29,970
Next, we assign the fitted values to our data frame for the rows corresponding to the train set.

28
00:02:33,880 --> 00:02:40,390
Next, we call forecast for test time steps, and we assign the result to our data frame for the rows

29
00:02:40,390 --> 00:02:41,890
corresponding to the test set.

30
00:02:45,910 --> 00:02:51,160
Now, when we plot the whole column, along with the original Time series, we can see both the sample

31
00:02:51,160 --> 00:02:54,340
predictions along with the out of sample forecast.

32
00:02:59,940 --> 00:03:05,370
As expected, we get a straight line at trending upwards, which is exactly what the whole linear trend

33
00:03:05,370 --> 00:03:07,930
model should it do in this scenario.
