So far, we've gone through quite a few steps from a simple moving average to the exponentially weighted
moving average to viewing the moving average as a predictive model and finally adding a trend component
in this lecture, we are going to complete this journey with the full winter's model.
The whole winters' model extends the whole linear trend model by adding a seasonal component.
This makes sense, especially for our data set, because there is a clear seasonal pattern.
In fact, for many time series data sets, there is a clear seasonal pattern.
Think of something like air conditioner sales.
Obviously, more people buy air conditioners in the summer than in the winter.
We have all kinds of sales that are seasonal, such as back to school sales, Boxing Day sales and nowadays
Black Friday sales, which I'm sure you're all familiar with.
So how does the whole winter's model work?
The basic idea is that for the kinds of Time series we would like to model, there are generally three
components.
There is the trend component, which we've seen.
There is the seasonal component, which we are just now seeing, and there is the level component,
which is sort of the average value around which everything else fluctuates.
These three combine together to form the full time series signal.
The question is how do we combine them together, in fact, for the whole winter's model?
There are two ways of doing this.
The first method is called the additive method for this model, the seasonal component or the periodic
component is simply added to the trend and the level.
So you can imagine a noisy line added to some periodic signal.
And this periodic signal being periodic does not change over time.
The second method is called the multiplicative method for this model.
The seasonal component changes proportional to the level of the Time series.
This seems like it might be a good fit for our data set, because it seems like the wavy part actually
increases in amplitude as the level gets larger and larger.
So let's look at the additive method in component form.
As usual, I think the best way to understand these models is to pay careful attention to each of these
equations.
The forecast equation is sort of the centerpiece of the model because it tells you how each of the components
combine to give you the full output.
So what does the forecast equation look like here?
Well, first, let's recognize that two thirds of this equation we've already seen this is just holds
linear trend model.
It says that for each step that H increases the non seasonal part of the forecast increases by B of
T.
The new part is the S term, which obviously corresponds to the seasonal component.
Now, you might find these indices very confusing at first, but we'll go through them slowly so you
understand what they mean.
First, we need to define this new variable M, which is used to define the period of the seasonal component.
Some people refer to this as the frequency, but it's more accurate to think of it as the period.
Remember, that period refers to the length of time that it takes for a signal to repeat itself.
For example, the period of the sine function and the cosine function is too high.
Frequency is actually inversely related to the period.
In any case, this is one of those variables that must be chosen manually.
But in real world situations, it probably won't be that hard.
As an example, if you're looking at sales data over each month, then we might expect the period to
be 12 since there are certain events that happen every year which affect sales.
Obviously, this will require some domain knowledge.
So the data science practitioner, that's you should apply what you know about the data to choose this
value correctly.
So now we know what M is.
We also know what T and since we've seen them before, T is just the last known time for which we have
real observations and the number of steps ahead that we are forecasting.
But what is K?
Let's ignore this strange formula for now.
Intuitively, K is a number chosen so that we look back the appropriate number of steps in our training
data to choose the correct seasonal component.
For example, suppose that our data goes up until December twenty twenty and the frequency of the data
is monthly.
Suppose that we would like to make a forecast for March twenty twenty one.
In this case, the training data is from December twenty twenty and any time before that to get the
seasonal component for the March twenty twenty one forecast, we would like to use the seasonal component
for the latest month of March that we know of, which is March twenty twenty.
We would not want to have, say, the seasonal component from November twenty twenty because that's
an entirely different month, which includes Black Friday, which definitely includes data we don't
care about in March.
On the other hand, note that the level L and the trend B both come from time t, the latest measurement,
only the seasonal component looks further back in time to grab the appropriate point over the entire
season.
If you're mathematically inclined, then we can do an example to make sure that this works, if you
are not mathematically inclined, then just understand that intuition and that's OK.
Remember that we're going to be using a library anyway, so let's suppose that we have it.
T equals thirty six and our data is monthly, so M equals 12.
Suppose that we want to forecast 15 steps into the future.
So H is equal to 15.
So if one refers to January then 12 refers to December as those twenty four and thirty six.
So our training data is three years from January to December.
Three years later, we want to predict 15 months into the future, which is March, but it's the March.
One year after the latest measurement, we know intuitively that the seasonal component should come
from T equals twenty seven Y, because that's the last known March measurement that we have.
In other words, the one that's closest to thirty six.
So let's see if our formula works, we have equal to the floor of each minus one over M plus one, if
we plug in all of our numbers, we get K equal to the floor of 14 over 12 plus one, which is all equal
to two.
Therefore, the time index for S will be thirty six plus fifteen minus twelve times two, which is equal
to twenty seven.
And thus we have confirmed that this strange formula does indeed work.
All right, so now that we understand the forecast equation, the others are pretty simple.
Next, we have the legal equation.
This is almost the same as the linear trend model.
And you should feel comfort about the fact that it's the same old exponential moving average.
The main difference is that we subtract the seasonal component from Y note that we subtract the previous
seasonal component at index T minus M.
This makes sense since in our equations generally, why is considered the forecast.
So it's always ahead of all the other components.
Next, we have the trend equation.
This one is exactly the same as before.
It's an exponential moving average of the trend as measured by the difference in levels.
Finally, we have the seasonal equation, this one might seem strange at first, but at least you can
recognize that this, again, is an exponential moving average in front of Gammer.
We have the new value and in front of one minus Gamma, we have the old value.
Again, recognize that the old value comes from one period ago rather than one timestep ago.
So that's why the previous S is indexed by T minus.
For the new value, this makes sense when you consider the forecast recall that Y is equal to the level
plus trend plus seasonal component.
Therefore the seasonal component is Y minus the level, minus the trend.
If you think of it like an equation, you're just moving the level in the trend to the other side to
isolate the seasonal part.
All right, so now that you understand the additive model, let's move on to the multiplicative model.
Since you already understand how the additive model works, it's not that much effort to understand
the multiplicative model as before.
Let's start with understanding the forecast equation based on the name of the model.
I think the forecast equation makes intuitive sense instead of adding the seasonal component.
We now take the linear part and multiply it by the seasonal component.
The general equation at a high level can be thought of as Y equals L plus B all times s for the level
update.
We now have Y divided by S.
That makes sense because before we had Y minus S.
For the trend equation, there is no change for the seasonal equation.
We have Y divided by L plus B that makes sense because before we had a Y minus O plus B.
All right, so as with our previous lectures, now that we understand the theory, we're going to discuss
the main parts of the code.
So first, we'll need a new class, which is simply called exponential smoothing.
This might be a little confusing since one might think of the Ummah as exponential smoothing.
But just remember that in this library, we qualify it by saying it's simple exponential smoothing.
So not simple.
Exponential smoothing refers to whole winters'.
Next, we instantiate our model in the constructor, we pass in the data, and we also specify whether
the trend and seasonal components are additive or multiplicative.
We also specify the period which in our case will be 12 since our data is monthly.
Note that in this lecture we discussed two models with a seasonal component was either additive or multiplicative
in both these cases.
The trend was additive.
Stat's models also gives you the option of making the trend a multiplicative if you think that fits
your data.
So that might apply when your trend curves rather than going in a straight line.
The next step is to call the fit function, which does not require any parameters.
And as usual, this returns.
A whole winters' results object from which we can then obtain the fitted values as well as call the
forecast function.