OK, so in this lecture, we will be looking at a new notebook that will explore a few different details
that we didn't previously cover.
This notebook will look at multiplicative seasonality, outliers and non daily time intervals.
As you recall, the Rassman data set contained daily data with additive seasonality.
So he wouldn't have been able to explore these other features.
So it will begin again by installing profit.
The next step is to download our data set.
The next step is to import profit, as well as other useful libraries from the numpties stock.
The next step is to load in our data using PDF that reads CSFI.
The next step is to call the head, just in case you forgot what this data looks like.
So as you can see, we have one column for passengers and the index is also the time stamp.
Notice that the sampling rate of our time series is once per month.
The next step is to rename our passengers column to Why as Profit Expects.
The next step is to assign the index to a column called D again as profit expects.
The next step is to call the head again to ensure that our data frame is in the right format.
The next step is to call the detail to check on our time series ends.
OK, so you can see that our time series ends at the end of nineteen sixty.
The next step is to instantiate our profit model.
The next step is to call it.
Notice that now we have even more messages coming from the fit function, this time we see that both
daily and weekly seasonality are turned off.
This makes sense since our data is monthly and therefore it wouldn't be possible to infer seasonality
at a smaller scale.
The next step is to call make future data frame.
Note that we now use an extra argument called Freekeh to specify that the periods are in months.
So in this case, we'll be making a one year forecast.
The next step is to call future detail, to confirm that it contains the months we expect.
So as you can see, the future data frame contains dates up to nineteen sixty one, which is one year
after the end of our Time series.
The next step is to call predict to obtain our predictions.
The next step is to call the plot function to plot our predictions.
We'll also use this opportunity to plot the change points as well.
OK, so this looks reasonable, but it's not perfect.
Notice how our model overestimates at the beginning and underestimates at the end, it's unable to model
the fact that the seasonal component increases in magnitude over time.
This is because by default, we have additive seasonality.
The next step is to plot the components of our model.
So here we can see that the trend increases somewhere in the middle and we seem to have an increase
in the summer months, which makes sense.
The next step is to create a second model with multiplicative seasonality.
We'll see whether or not this does a better job.
The next step is to call it.
The next step is to call make future data frame with the same arguments as before.
The next step is to predict, as we did before.
The next step is to plot the forecast along with the change point's.
OK, so as you can see, the model now does a much better job of matching the peaks and troughs, both
when the seasonal component is small and when it is large.
Note that the change points are not really that sensible because we're still using a linear model of
growth.
So as an exercise, you may want to try experimenting with logistic growth.
Note that I've tried this myself, but the result didn't look particularly good, at least with the
settings I chose.
The next step is to plot the components.
As you can see, we again get a peak in the summer, which is to be expected.
Now, as you recall, one way we can avoid having to use multiplicative seasonality is to simply take
the log of the data.
So in this next step, we're going to take the log of the Y column and make a new data frame called
Log The.
The next step is to create our third model and three.
The next step is to call fit once again.
The next step is to call make future data frame once again.
The next step is to call predict once again.
The next step is to plot the forecast along with the checkpoints once again.
OK, so as you can see, this model is probably a bit too sensitive with this change points, however,
note that it has no issue with the seasonal component thanks to the log transform.
The next step is to plot the seasonal components.
As you can see, we still get a peak in the summer, which is what we would expect.
OK, so in the next part of this notebook, we are going to investigate what happens when you have our
lives.
We'll begin by making some fake outliers.
So on January one, 1955, I've set the value to 600, which is much larger than normal.
On June one nineteen fifty seven, I've set the value to one which is much smaller than normal.
The next step is to plot our Time series with the new outliers.
So as you can see, there is one part where the Time series is uncharacteristically high and another
where it is uncharacteristically low.
The next step is to create a model with multiplicative seasonality, we'll do the fitting and predicting
as well, since you're already familiar with these steps.
OK, so notice that our model still appears to fit quite well, but there is one big difference.
This is that the prediction interval is very large compared to what it was before.
This is due to the outliers.
And this makes sense since if the model has seen very large or very small values, it may expect to
see them again in the future, making it less confident in its own predictions.
OK, so how do we deal with outliers?
Well, recall that profit is essentially a continuous time model.
Time is the only aggressor, so missing data is essentially a non-issue.
Thus, the recommended method of dealing with outliers is to simply remove them.
We're going to do this by simply creating a new data frame called data that does not include the two
outlier dates we previously chose.
The next step is to plot our new time series with the outliers removed.
As you can see, it's essentially no different from before.
The next step is to build a new model and fit it on our Time series with our lives removed.
So as you can see, we now get a much better fit in addition and notice how the prediction intervals
are, again, very small since there is no need to account for large deviations.