In this lecture, we are going to bridge the gap between exponential smoothing and the whole winters'
model.
This is going to be done in a series of steps.
And the first step is to understand exponential smoothing from a different perspective.
That is from the perspective of Time series forecasting.
Previously, our perspective was simply what are different ways that we can take the average in a time
series.
Now it's more about how do we fit a model to the Time series and then how do we use that model to forecast
future values?
Mathematically, this is the same as before, but philosophically it's different.
To do this, we're going to have to introduce some new and more precise notation.
Let's begin by reviewing the exponentially weighted moving average once again, but using our new notation.
So now we have we had a time t equal to Alpha times Y of T plus one minus Alpha times.
We had a time T minus one in this form.
Y had a time.
T is our exponentially smooth version of Y at time t y it is the value from our time series at time.
T Alpha is again the smoothing parameter.
The next step is to now phrase this as a forecasting model, in this form, the equation looks as follows.
You'll notice that I've introduced this vertical bar symbol, which, as you know, in probability means
given some on the left hand side, we're saying why hat is the exponentially smooth forecast for a time
T plus one given the known values at time t on the right hand side we have alpha times Y of T as usual,
plus one minus four times the previous exponentially smooth value.
Noticed something interesting about this, the time indices have changed for the current equation,
the Y hat on the left is for the time index T plus one, the Y hat on the right has the time index T.
If you look at the previous slide at the time and next is on the left and at T minus one is on the right.
This is probably extremely confusing at this point.
And I wouldn't blame you for thinking so.
It will make much more sense when we look at the code and you actually observe this behavior for yourself.
Now, realize that I didn't invent this.
This is all part of the whole winters' model.
So don't blame me if you find it confusing.
By the time we reach the full whole Winsor's model and you see it in action, you will see that this
all makes sense.
Again, recognize that this is now a forecast.
Previously we were not forecasting, we were just calculating averages.
The forecast for the next timestep is equal to Alpha Times, the currently observed value plus one minus
alpha times, the current exponentially smooth's fitted value.
The next step is to express the simple exponential smoothing model in what is called component form.
This will make it seem like overkill at this point because there is only a single component.
However, the whole winters' model contains multiple components, which is where this becomes useful.
So in this form, the forecast equation looks as follows.
We say that we had a time at T plus H given T is equal to live T, that is the forecast at an arbitrary
eight steps ahead is equal to Helft, whatever that is.
Then the smoothing equation says this elev T is just the exponentially smooth average of Y of t the
Time series.
Notice that L.A. now becomes the exponentially smooth average and Y hat becomes the forecast.
Also, note that L.A. gets back its original time indices from the previous lecture, that is, we now
have tea on the left and T minus one on the right.
So left is itself not a forecast, but the forecast is based on liberty for this simple model.
The forecast is simply assigned it to be a.
But this will get more complex in later lectures.
So what does Aloft represent?
LTE is called the level, which will become more clear when we put it into context later on.
Basically level can be thought of as the moving average, which kind of makes sense.
The level is the average value of the signal in time, but the actual signal may fluctuate around that
average level.
One important thing to note about this forecasting model is that it's not very expressive.
The forecast is simply a constant value.
It's always left no matter how many steps ahead you want to forecast.
This must be the case because remember, the exponentially weighted moving average is nothing but an
estimate of the mean, since all we're estimating is the mean and that's the only thing we can predict
after we've stopped collecting data.
We have no idea how this will change beyond the last known data point.
And so our forecast simply consists of predicting the same mean value for each timestep.
The last thing we were going to do in this lecture is talk about how this will work in code.
Previously we looked at pandas as a way to calculate the exponentially weighted moving average.
And we've noted that this lecture didn't introduce any new concepts other than some renaming of variables.
However, in the next coding lecture, we're going to use stats models to perform exponential smoothing,
which has a model that works more in line with what we discussed in this lecture.
Furthermore, it's capable of making forecasts so that will allow us to use exponential smoothing as
a predictive model rather than just some way of taking the average.
So how does it work, since this is the first model from stat's models will be looking at in this course,
how it works might be surprising if you come from a cyclone background.
Basically, remember that this is a different library, so it has a different API.
First, we start by importing the class, simple smoothing from the whole winters' module inside stat's
models.
Next, we create a model by instantiating an object of type, simple, smoothy.
Note that when doing this, we pass in the data set, which should be a univariate time series, unlike
Saikat Learn, which expects a two dimensional array, is input.
This model expects a one dimensional array because the only dimension is time inside.
It learn its number of samples by a number of features.
Also, notice that, unlike Saikat, learn where the data is passed into the fit function with stats
models, the data is passed into the constructor.
The stats models object does have a fit function, which is what we will call next its function, except
some parameters such as Alpha.
So it's kind of like the reverse of Saikat, learn in Saikat, learn at the constructor.
It usually takes in the hyper parameters and the fit function it takes in the data in stats models,
the constructor takes in the data and the fit function takes in the hyper parameters for us.
We're going to pass in Alpha into the fit function in addition to setting the argument optimized equal
false.
Note that for all of the models in the whole WINTERS' module, it's possible to fit parameters to the
data.
This makes it more like machine learning than simply calculating a moving average.
But this will make more sense as our model gets more and more complex in later lectures.
In order to make what we're doing equivalent to what we did previously, we will not try to optimize
the value of Alpha.
Basically, Alpha would be optimized in order to minimize the error on the training set.
If you're familiar with machine learning, then you will understand that this involves taking the mean
squared error between the true Time series and the predicted values and then minimizing that with respect
to Alpha.
If you're not comfortable with this idea, it's not necessary to know.
So don't worry about it since we're not going to use it anyway.
All right, so the fit function returns a result object, which is again different from what you're
probably familiar with from Saikat, learn in Saikat, learn you just get a reference to the model object
itself.
In stat's models, we get a result object.
Specifically, we get back a whole winters' results object so you can look up the documentation if you're
interested in seeing what functions can be called on this object.
The first function we are interested in is the predictive function, the way it works is this you pass
in a start date for the start argument and an end date for the end argument.
And then this will return an array containing a prediction of time series values for those dates.
Note that these dates can be in sample or out of sample, meaning that they can be dates from the training
set or after the training set, if the predicted dates are from inside the range of the train set,
we call that an N sample prediction.
If the prediction dates are from outside the range of the train set, we call that an out of sample
forecast.
A simpler way to get predictions is this if you want all of the train predictions, you simply call
the attribute fitted values.
This way you can avoid having to figure out the dates that you need for the start and end arguments.
A simpler way to get a forecast is to simply call a forecast function.
This accepts as input the number of forecasting steps.
So, for example, if you want to forecast ten steps ahead, you just pass in 10.
There's no need to figure out what the data is.
10 steps ahead.
Passing in the Integer 10 is enough.
Note that this assumes that your forecast begins at the timestep after the end of the train set.
So if your train set goes from one up to Big T., then your first forecast prediction will be for the
time index, big T plus one.