1
00:00:11,120 --> 00:00:16,550
So far, we've gone through quite a few steps from a simple moving average to the exponentially weighted

2
00:00:16,550 --> 00:00:22,340
moving average to viewing the moving average as a predictive model and finally adding a trend component

3
00:00:22,910 --> 00:00:27,800
in this lecture, we are going to complete this journey with the full winter's model.

4
00:00:28,430 --> 00:00:33,350
The whole winters' model extends the whole linear trend model by adding a seasonal component.

5
00:00:34,160 --> 00:00:38,840
This makes sense, especially for our data set, because there is a clear seasonal pattern.

6
00:00:39,360 --> 00:00:43,520
In fact, for many time series data sets, there is a clear seasonal pattern.

7
00:00:44,090 --> 00:00:46,520
Think of something like air conditioner sales.

8
00:00:46,760 --> 00:00:50,770
Obviously, more people buy air conditioners in the summer than in the winter.

9
00:00:51,320 --> 00:00:56,900
We have all kinds of sales that are seasonal, such as back to school sales, Boxing Day sales and nowadays

10
00:00:57,080 --> 00:01:00,140
Black Friday sales, which I'm sure you're all familiar with.

11
00:01:04,840 --> 00:01:06,820
So how does the whole winter's model work?

12
00:01:07,420 --> 00:01:12,820
The basic idea is that for the kinds of Time series we would like to model, there are generally three

13
00:01:12,820 --> 00:01:13,670
components.

14
00:01:13,990 --> 00:01:16,240
There is the trend component, which we've seen.

15
00:01:16,660 --> 00:01:21,910
There is the seasonal component, which we are just now seeing, and there is the level component,

16
00:01:21,910 --> 00:01:26,120
which is sort of the average value around which everything else fluctuates.

17
00:01:26,770 --> 00:01:30,310
These three combine together to form the full time series signal.

18
00:01:31,120 --> 00:01:36,020
The question is how do we combine them together, in fact, for the whole winter's model?

19
00:01:36,220 --> 00:01:37,810
There are two ways of doing this.

20
00:01:42,740 --> 00:01:48,590
The first method is called the additive method for this model, the seasonal component or the periodic

21
00:01:48,590 --> 00:01:51,610
component is simply added to the trend and the level.

22
00:01:52,160 --> 00:01:56,090
So you can imagine a noisy line added to some periodic signal.

23
00:01:56,270 --> 00:02:00,380
And this periodic signal being periodic does not change over time.

24
00:02:01,070 --> 00:02:05,090
The second method is called the multiplicative method for this model.

25
00:02:05,120 --> 00:02:09,800
The seasonal component changes proportional to the level of the Time series.

26
00:02:10,750 --> 00:02:15,880
This seems like it might be a good fit for our data set, because it seems like the wavy part actually

27
00:02:15,880 --> 00:02:19,360
increases in amplitude as the level gets larger and larger.

28
00:02:24,240 --> 00:02:27,100
So let's look at the additive method in component form.

29
00:02:27,690 --> 00:02:33,120
As usual, I think the best way to understand these models is to pay careful attention to each of these

30
00:02:33,120 --> 00:02:33,970
equations.

31
00:02:34,500 --> 00:02:40,080
The forecast equation is sort of the centerpiece of the model because it tells you how each of the components

32
00:02:40,230 --> 00:02:42,000
combine to give you the full output.

33
00:02:42,750 --> 00:02:45,060
So what does the forecast equation look like here?

34
00:02:45,750 --> 00:02:51,700
Well, first, let's recognize that two thirds of this equation we've already seen this is just holds

35
00:02:51,720 --> 00:02:52,690
linear trend model.

36
00:02:53,370 --> 00:02:59,730
It says that for each step that H increases the non seasonal part of the forecast increases by B of

37
00:02:59,730 --> 00:03:00,150
T.

38
00:03:01,170 --> 00:03:05,670
The new part is the S term, which obviously corresponds to the seasonal component.

39
00:03:06,480 --> 00:03:10,920
Now, you might find these indices very confusing at first, but we'll go through them slowly so you

40
00:03:10,920 --> 00:03:12,150
understand what they mean.

41
00:03:13,050 --> 00:03:19,020
First, we need to define this new variable M, which is used to define the period of the seasonal component.

42
00:03:19,770 --> 00:03:24,810
Some people refer to this as the frequency, but it's more accurate to think of it as the period.

43
00:03:25,290 --> 00:03:30,360
Remember, that period refers to the length of time that it takes for a signal to repeat itself.

44
00:03:30,690 --> 00:03:35,670
For example, the period of the sine function and the cosine function is too high.

45
00:03:36,570 --> 00:03:39,790
Frequency is actually inversely related to the period.

46
00:03:40,500 --> 00:03:44,210
In any case, this is one of those variables that must be chosen manually.

47
00:03:44,370 --> 00:03:47,690
But in real world situations, it probably won't be that hard.

48
00:03:48,180 --> 00:03:53,760
As an example, if you're looking at sales data over each month, then we might expect the period to

49
00:03:53,760 --> 00:03:58,560
be 12 since there are certain events that happen every year which affect sales.

50
00:03:59,430 --> 00:04:02,010
Obviously, this will require some domain knowledge.

51
00:04:02,160 --> 00:04:07,920
So the data science practitioner, that's you should apply what you know about the data to choose this

52
00:04:07,920 --> 00:04:08,870
value correctly.

53
00:04:09,900 --> 00:04:11,340
So now we know what M is.

54
00:04:11,580 --> 00:04:17,580
We also know what T and since we've seen them before, T is just the last known time for which we have

55
00:04:17,580 --> 00:04:21,830
real observations and the number of steps ahead that we are forecasting.

56
00:04:22,350 --> 00:04:23,340
But what is K?

57
00:04:23,910 --> 00:04:26,160
Let's ignore this strange formula for now.

58
00:04:26,670 --> 00:04:32,730
Intuitively, K is a number chosen so that we look back the appropriate number of steps in our training

59
00:04:32,730 --> 00:04:35,460
data to choose the correct seasonal component.

60
00:04:36,120 --> 00:04:42,000
For example, suppose that our data goes up until December twenty twenty and the frequency of the data

61
00:04:42,000 --> 00:04:42,740
is monthly.

62
00:04:43,890 --> 00:04:47,810
Suppose that we would like to make a forecast for March twenty twenty one.

63
00:04:48,480 --> 00:04:55,290
In this case, the training data is from December twenty twenty and any time before that to get the

64
00:04:55,290 --> 00:05:01,590
seasonal component for the March twenty twenty one forecast, we would like to use the seasonal component

65
00:05:01,830 --> 00:05:05,910
for the latest month of March that we know of, which is March twenty twenty.

66
00:05:06,720 --> 00:05:11,940
We would not want to have, say, the seasonal component from November twenty twenty because that's

67
00:05:11,940 --> 00:05:16,920
an entirely different month, which includes Black Friday, which definitely includes data we don't

68
00:05:16,920 --> 00:05:18,000
care about in March.

69
00:05:19,100 --> 00:05:25,820
On the other hand, note that the level L and the trend B both come from time t, the latest measurement,

70
00:05:26,450 --> 00:05:32,270
only the seasonal component looks further back in time to grab the appropriate point over the entire

71
00:05:32,270 --> 00:05:32,830
season.

72
00:05:37,850 --> 00:05:43,220
If you're mathematically inclined, then we can do an example to make sure that this works, if you

73
00:05:43,220 --> 00:05:48,230
are not mathematically inclined, then just understand that intuition and that's OK.

74
00:05:48,920 --> 00:05:53,470
Remember that we're going to be using a library anyway, so let's suppose that we have it.

75
00:05:53,480 --> 00:05:57,700
T equals thirty six and our data is monthly, so M equals 12.

76
00:05:58,430 --> 00:06:01,860
Suppose that we want to forecast 15 steps into the future.

77
00:06:02,090 --> 00:06:03,820
So H is equal to 15.

78
00:06:04,520 --> 00:06:10,700
So if one refers to January then 12 refers to December as those twenty four and thirty six.

79
00:06:11,770 --> 00:06:15,700
So our training data is three years from January to December.

80
00:06:15,860 --> 00:06:22,430
Three years later, we want to predict 15 months into the future, which is March, but it's the March.

81
00:06:22,430 --> 00:06:28,400
One year after the latest measurement, we know intuitively that the seasonal component should come

82
00:06:28,400 --> 00:06:34,210
from T equals twenty seven Y, because that's the last known March measurement that we have.

83
00:06:34,670 --> 00:06:37,370
In other words, the one that's closest to thirty six.

84
00:06:42,080 --> 00:06:49,820
So let's see if our formula works, we have equal to the floor of each minus one over M plus one, if

85
00:06:49,820 --> 00:06:56,570
we plug in all of our numbers, we get K equal to the floor of 14 over 12 plus one, which is all equal

86
00:06:56,570 --> 00:06:57,190
to two.

87
00:06:57,920 --> 00:07:05,180
Therefore, the time index for S will be thirty six plus fifteen minus twelve times two, which is equal

88
00:07:05,180 --> 00:07:06,050
to twenty seven.

89
00:07:06,470 --> 00:07:10,610
And thus we have confirmed that this strange formula does indeed work.

90
00:07:15,280 --> 00:07:19,450
All right, so now that we understand the forecast equation, the others are pretty simple.

91
00:07:20,110 --> 00:07:21,780
Next, we have the legal equation.

92
00:07:22,300 --> 00:07:24,820
This is almost the same as the linear trend model.

93
00:07:25,000 --> 00:07:29,740
And you should feel comfort about the fact that it's the same old exponential moving average.

94
00:07:30,370 --> 00:07:36,820
The main difference is that we subtract the seasonal component from Y note that we subtract the previous

95
00:07:36,820 --> 00:07:39,560
seasonal component at index T minus M.

96
00:07:40,180 --> 00:07:44,950
This makes sense since in our equations generally, why is considered the forecast.

97
00:07:45,130 --> 00:07:47,590
So it's always ahead of all the other components.

98
00:07:52,250 --> 00:07:53,880
Next, we have the trend equation.

99
00:07:54,530 --> 00:07:56,810
This one is exactly the same as before.

100
00:07:57,230 --> 00:08:02,060
It's an exponential moving average of the trend as measured by the difference in levels.

101
00:08:06,870 --> 00:08:12,150
Finally, we have the seasonal equation, this one might seem strange at first, but at least you can

102
00:08:12,150 --> 00:08:17,730
recognize that this, again, is an exponential moving average in front of Gammer.

103
00:08:17,730 --> 00:08:21,690
We have the new value and in front of one minus Gamma, we have the old value.

104
00:08:22,320 --> 00:08:28,330
Again, recognize that the old value comes from one period ago rather than one timestep ago.

105
00:08:28,620 --> 00:08:31,740
So that's why the previous S is indexed by T minus.

106
00:08:33,170 --> 00:08:38,570
For the new value, this makes sense when you consider the forecast recall that Y is equal to the level

107
00:08:38,570 --> 00:08:40,580
plus trend plus seasonal component.

108
00:08:41,240 --> 00:08:45,720
Therefore the seasonal component is Y minus the level, minus the trend.

109
00:08:46,280 --> 00:08:50,870
If you think of it like an equation, you're just moving the level in the trend to the other side to

110
00:08:50,870 --> 00:08:52,160
isolate the seasonal part.

111
00:08:57,100 --> 00:09:01,810
All right, so now that you understand the additive model, let's move on to the multiplicative model.

112
00:09:02,470 --> 00:09:07,270
Since you already understand how the additive model works, it's not that much effort to understand

113
00:09:07,270 --> 00:09:10,000
the multiplicative model as before.

114
00:09:10,210 --> 00:09:15,500
Let's start with understanding the forecast equation based on the name of the model.

115
00:09:15,520 --> 00:09:20,810
I think the forecast equation makes intuitive sense instead of adding the seasonal component.

116
00:09:21,040 --> 00:09:24,910
We now take the linear part and multiply it by the seasonal component.

117
00:09:25,630 --> 00:09:33,160
The general equation at a high level can be thought of as Y equals L plus B all times s for the level

118
00:09:33,160 --> 00:09:33,590
update.

119
00:09:33,610 --> 00:09:35,620
We now have Y divided by S.

120
00:09:35,950 --> 00:09:39,160
That makes sense because before we had Y minus S.

121
00:09:40,330 --> 00:09:44,570
For the trend equation, there is no change for the seasonal equation.

122
00:09:44,590 --> 00:09:50,890
We have Y divided by L plus B that makes sense because before we had a Y minus O plus B.

123
00:09:55,830 --> 00:10:00,990
All right, so as with our previous lectures, now that we understand the theory, we're going to discuss

124
00:10:00,990 --> 00:10:02,620
the main parts of the code.

125
00:10:03,120 --> 00:10:07,450
So first, we'll need a new class, which is simply called exponential smoothing.

126
00:10:08,070 --> 00:10:13,240
This might be a little confusing since one might think of the Ummah as exponential smoothing.

127
00:10:13,560 --> 00:10:19,490
But just remember that in this library, we qualify it by saying it's simple exponential smoothing.

128
00:10:19,830 --> 00:10:21,030
So not simple.

129
00:10:21,030 --> 00:10:23,670
Exponential smoothing refers to whole winters'.

130
00:10:24,640 --> 00:10:31,360
Next, we instantiate our model in the constructor, we pass in the data, and we also specify whether

131
00:10:31,360 --> 00:10:35,200
the trend and seasonal components are additive or multiplicative.

132
00:10:35,710 --> 00:10:40,580
We also specify the period which in our case will be 12 since our data is monthly.

133
00:10:41,620 --> 00:10:47,800
Note that in this lecture we discussed two models with a seasonal component was either additive or multiplicative

134
00:10:48,160 --> 00:10:49,300
in both these cases.

135
00:10:49,330 --> 00:10:50,710
The trend was additive.

136
00:10:51,610 --> 00:10:56,710
Stat's models also gives you the option of making the trend a multiplicative if you think that fits

137
00:10:56,710 --> 00:10:57,370
your data.

138
00:10:57,970 --> 00:11:01,790
So that might apply when your trend curves rather than going in a straight line.

139
00:11:02,710 --> 00:11:06,970
The next step is to call the fit function, which does not require any parameters.

140
00:11:07,330 --> 00:11:09,010
And as usual, this returns.

141
00:11:09,010 --> 00:11:14,020
A whole winters' results object from which we can then obtain the fitted values as well as call the

142
00:11:14,020 --> 00:11:15,060
forecast function.
