1
00:00:11,080 --> 00:00:17,060
OK, so for this code, the main idea is not to focus on every line, but to focus on what is different.

2
00:00:17,650 --> 00:00:20,860
You'll notice that most of this is the same as what we had before.

3
00:00:23,520 --> 00:00:28,950
So when we build our supervised data set, notice that we now use the difference in log passengers,

4
00:00:29,610 --> 00:00:33,660
also notice that we start from index one instead of taking the full array.

5
00:00:34,380 --> 00:00:38,640
This is because due to taking the first difference, the first value is zero.

6
00:00:49,680 --> 00:00:55,660
The next thing to notice is that R squared is much lower than before with a stationary time series.

7
00:00:55,800 --> 00:01:00,990
We can't simply predicts the previous value, which you've seen leads to a higher squared in particular

8
00:01:00,990 --> 00:01:01,710
cases.

9
00:01:04,050 --> 00:01:09,150
The next thing to notice is that for the train index, we now said the first big plus one values to

10
00:01:09,150 --> 00:01:09,780
false.

11
00:01:10,260 --> 00:01:12,210
Previously this was just big T.

12
00:01:16,390 --> 00:01:22,330
The next step is to compute the previous values, which we need to d difference our predictions for

13
00:01:22,330 --> 00:01:26,890
one step predictions, we can do this simply by shifting the log passengers up by one.

14
00:01:30,610 --> 00:01:35,650
For multistep predictions, we have to keep in mind that we only know the values from the train set,

15
00:01:36,280 --> 00:01:39,970
so we take the last value from the train set and we call that last train.

16
00:01:43,610 --> 00:01:49,190
OK, so let's see how to do the One-Step forecast for the train set, we take the shifted values in

17
00:01:49,190 --> 00:01:51,940
the train and add them to our predictions.

18
00:01:52,400 --> 00:01:57,200
You should recognize this from the equations we saw earlier for the test set.

19
00:01:57,210 --> 00:01:58,220
We do the same thing.

20
00:01:58,910 --> 00:02:02,180
Notice that this only applies to the ones that forecast.

21
00:02:10,420 --> 00:02:15,850
So you can see that the results look pretty good, much better than before, we now do not have a problem

22
00:02:15,850 --> 00:02:16,810
reaching the peak.

23
00:02:20,310 --> 00:02:23,870
The next step is to look at the incremental multistep forecast.

24
00:02:24,660 --> 00:02:27,810
Now, the loop to make the incremental predictions is the same.

25
00:02:28,320 --> 00:02:29,780
This gives us our deltas.

26
00:02:30,450 --> 00:02:33,270
The part that's different is what we do with these deltas.

27
00:02:38,350 --> 00:02:43,270
So this time it's a multi-step forecast, so the last known value comes from the train.

28
00:02:44,560 --> 00:02:49,270
So we take the last train value and add it to the cumulative some of the deltas.

29
00:02:56,340 --> 00:02:59,660
So we see that the multistep prediction is also pretty good.

30
00:03:03,650 --> 00:03:08,870
OK, so again, most of this stuff like the code to build the data set is the same as before.

31
00:03:20,860 --> 00:03:25,660
Notice again that the R-squared is lower because we're trying to predict a time series where there isn't

32
00:03:25,660 --> 00:03:27,640
a lot of correlation in the values.

33
00:03:31,000 --> 00:03:37,120
OK, so again, the forecast is the last train value, plus the cumulative some of the predictions.

34
00:03:44,680 --> 00:03:49,190
So we again see that the forecast is pretty good, but it's hard to tell from this plot.

35
00:03:49,210 --> 00:03:50,320
Which one is best?

36
00:03:56,110 --> 00:04:01,090
So when we look at the map, we see that the multipotent forecast achieves the best value.

37
00:04:05,080 --> 00:04:11,260
OK, so the next part is, again, to test different models, so this function follows exactly the same

38
00:04:11,260 --> 00:04:11,770
pattern.

39
00:04:12,280 --> 00:04:17,440
The only difference, again, is that we use our new calculations to difference the predictions.

40
00:04:24,330 --> 00:04:26,760
OK, so let's try the support vector machine.

41
00:04:31,740 --> 00:04:34,430
So the support vector machine doesn't do too well.

42
00:04:37,500 --> 00:04:39,660
The next step is to try the random forest.

43
00:04:45,230 --> 00:04:48,890
So this does pretty well, it seems to be on par with linear regression.

44
00:04:51,920 --> 00:04:54,810
The next step is to look at the multi output forecast.

45
00:04:55,490 --> 00:04:58,150
So, again, there's nothing really different about this function.

46
00:05:03,050 --> 00:05:07,520
Now, recall that the support vector machine does not support having multiple outputs.

47
00:05:08,360 --> 00:05:14,100
However, this does not stop us from simply creating our own SVM that can handle multiple outputs.

48
00:05:14,540 --> 00:05:19,340
It simply means we're going to create a separate support vector machine, one for each time step of

49
00:05:19,340 --> 00:05:20,270
the forecast.

50
00:05:24,010 --> 00:05:30,100
So here you can see I've created my own class called SVR wrapper in the constructor, we take in the

51
00:05:30,100 --> 00:05:37,420
forecast horizon and generic keyword arguments, which will be passed on to the SVR constructor inside

52
00:05:37,420 --> 00:05:38,250
the constructor.

53
00:05:38,260 --> 00:05:44,740
We simply save the forecast horizon and we instantiate multiple SVR objects, one for each time step

54
00:05:45,850 --> 00:05:47,200
inside the fit function.

55
00:05:47,230 --> 00:05:51,490
We simply call fit for each SVR, for each column of the target matrix.

56
00:05:51,970 --> 00:05:57,060
Inside the predicts function, we simply call predict for each SVR and then stack the result.

57
00:05:57,730 --> 00:05:59,230
Notice that we use each stack.

58
00:05:59,230 --> 00:06:05,710
Since each output is an end length vector, the result will be a new array of size n by the forecast

59
00:06:05,710 --> 00:06:06,370
horizon.

60
00:06:11,520 --> 00:06:15,600
OK, so in the next block, we're going to test our custom SVR rapper.

61
00:06:19,870 --> 00:06:22,190
Notice how it still does not perform too well.

62
00:06:22,570 --> 00:06:27,700
It seems like this is simply not a good model for this Time series, but note that you can still tune

63
00:06:27,700 --> 00:06:28,780
the hyper parameters.

64
00:06:35,620 --> 00:06:42,040
OK, so we see that the random forest does very well notice how much better it performs when we do different

65
00:06:42,040 --> 00:06:42,370
saying.
