OK, so in this lecture, we will continue looking at our CoLab notebook and building different profit
models for our Time series.
This lecture will focus on how to incorporate holidays and exogenous progressors, which we have not
yet done.
So we'll start by creating a new profit model, which we will call M3.
The next step is do simply call the function, add country holidays now, please note that this is for
demonstration purposes only.
As you recall, our data set is for a drug story in Europe.
Unfortunately, there is no data about which particular country any stores from as far as I've looked,
although to be fair, I haven't spent much time doing so.
Thus in this lecture, we are simply going to pass in the country, name us and practice.
You will, of course, have a better idea of what the relevant country is, either because you live
there or your client will tell you.
OK, so after this, the steps pretty much remain the same, the next step is to call fit.
We're going to use the second data frame, which does not include the days the store was closed.
The next step is to call make future data frame for a one year forecast.
The next step is to call it.
The next step is to plot the forecast and check our results.
Now, it's not clear how well we are actually doing, since this looks pretty similar to our previous
plot.
We'll look at numerical metrics later in this lecture.
The next step is to call Plott component's.
So as you can see, there is now one extra component which shows the influence of each holiday.
OK, so in the next portion of code, we're going to look at how to add exoticness or grassers.
Now, for the previous example, we did things the lazy way, which was to just call a function that
automatically adds the holidays for a particular country.
If that works for you, then you should use that.
But if not, then this is an example of how you can do a similar thing, but in a more customized way.
So as you recall, the original data set actually includes holidays already.
So the first thing we're going to do here is check the unique values of the column called State Holiday.
As you can see, there are four different values, zero, A, B and C now you'll have to check Kagle
for this, but zero means no.
Holiday means public holiday.
B means Easter and C means Christmas.
The next step is to check school holiday.
So in this case, we only have two values, zero or one.
The next step is to add these new columns to our profit data frame.
So in the basic case, the profit data frame should only contain ads and why?
But when you add exogenous progressors, then you can add new columns.
So we'll start by adding open and promo, which are just binary, either zero or one.
The next step is to add the state holiday.
Now, we previously saw that these were letters.
Of course, statistical models don't know what to do with letters since they are mathematical formulas
that only work on numbers.
Thus, what we will do is Dommy encode these values using peaty that get dummy's note that we use drop
first equals true in order to use dummy encoding instead of one hot encoding.
One hot encoding will give us four values, but dummy encoding will give us three values.
The fourth value is redundant, so we don't need to include it.
So this will return three columns, which we will assign to be S.H. one, two and three.
The final step is to add a school holiday, which is simpler because it's just zero or one.
The next step is to call the head function to see what our new data frame looks like.
OK, so as you can see, we have some new columns which correspond to the previous code we just ran.
The next step is to create our next model, which we will call them for this time, what we need to
do before calling fit is to call a function at a agressor.
Note that this takes in one required argument, which is the name of the column for the aggressor.
The second argument is optional, and this specifies how the aggressor should be incorporated into the
model.
The default is to use the seasonality mode, but if you want to choose this yourself, you can choose
additive or multiplicative.
Now you'll see that I've chosen multiplicative for open.
My hope for this is that the model will figure out when the store is closed.
You should multiply by zero to get zero.
Of course, there is no guarantee that this is how the model actually works.
OK, so once we've added all our progressors, we can call it.
The next step is to call make future data frame, as we usually do.
The next step is to create a train IDEX ancestrally, which will be used to index the future data frame,
since both the sample data and out of sample data are included in the same object.
What we're going to do here is check whether or not the DSS value is in the index for the input data
frame.
If that is the case, then of course it belongs to the Transat.
The test index is simply the opposite.
The next step is to add the aggressors to the future data frame, which is required in order to make
predictions.
Recall that this is the same as it is with the rhema.
If you want to use exogenous or aggressors, then you need to specify the input values to be used for
each prediction.
So in this first block, we're going to do this for the Transat, which is easy because it's just a
copy of what we had before.
This will be more difficult for the test set because we don't actually know when the store will be closed
or when there will be a holiday in this European country.
So we'll start by creating a list of exoticness or grassers.
The next step is to live through each one.
Inside the loop will index future for on the left side by train.
IDEX specifying the current column are on the right side.
We simply grab the column are from our input data frame and convert that into a list.
So the difficult part is for the test set in this case, we're going to take a very lazy approach and
just assume that the store will not be open on Sundays, which we've seen for all the other progressors.
We are simply going to copy them from the train set for the past three hundred sixty five days.
Of course, in the real world, your client would simply give you this information or you would get
it yourself based on the specifics of your project for this example, it doesn't really matter what
they are since we don't have the true targets anyway.
The next step is to call future for Ducktail to see what our new data frame looks like.
So notice the difference between the previous example, where we had no progressors and this example,
when we do in the previous example where we had no progressors, the future for data frame contained
only the column D When we do have aggressor's, we have to include those progressors.
OK, so the next step is do call predict as usual.
The next step is to plot our forecast.
OK, so notice how these results were not quite what we expected.
The model still gives us negative values and it still doesn't know that the sales are zero when the
store is not open.
What this tells us is that it's probably better to simply remove those days from the Time series.
The next step is to call Plott component's.
So, again, for the weekly seasonality, we see that Sun has a very negative influence.
Furthermore, for the yearly seasonality, we still see a peak around the winter holiday.
So we can see that adding the new regressions did not completely account for these events.
Also, notice that when we add extra progressors, their components are also plotted, so here we can
see two separate plots for both the additive and multiplicative components.