I remember the first time I told a client that possibly I could do a time series analysis and project
what their sales might be next quarter.
I remember he looked at me just dumbfounded that that was even possible.
And then when I showed him how it worked, he got really excited time series forecasting.
And you see it here in this example.
And we're going to cover this in depth in just a moment is a really important area of machine learning
as it gives you the ability to see ahead or forecast ahead of time and then make plans in your business
accordingly.
So Time series is really a collection of data at regular intervals, and that could be in days, maybe
even hours, months and years.
Here we're looking at data in years, I mean, in days.
So we have daily sales data in the Kento so database where we have days along the X axis and then sales
amounts on the Y axis.
So, again, Time series forecasting is a machine learning technique, and it analyzes data and during
the sequence of time to attempt to predict future events.
And this technique provides pretty accurate assumptions about future trends based on historical time
series data.
Of course, it's not perfect, but sometimes it's amazing how close it comes.
So Time series allows you to analyze patterns in your data, such as trends, maybe seasonality, cycles
of data irregularities and so on.
And it can be used in various applications such as stock market analysis, sales analysis like we're
doing here, pattern recognition, you know, weather forecasting, predicting, you know, natural
events like earthquakes, census analysis, other economic forecasting and so on.
So Time series includes, you know, trends and cycles and seasonality, and really a trend is just
an increase or decrease in data over a period of time.
And it's called a trend.
And you can get in fact, what we can do here is we could add we can come to let's see here, we could
get to a go to trend and add a trend line and we can see how this data is trending over time.
And that's what that's what TIME series forecast attempts to do is to determine trending in data.
That's one thing it can do.
And then it also identifies seasonal movements in data.
Now, seasonality generally is a fixed period or a fixed and known frequency like seasonal like like
the holidays, the Christmas holidays here in the United States.
You know, you can factor that into your seasonal factors and then project what that's going to do to
your sales for a particular period of days or weeks or months.
And then you've got cyclical data, which is cycles in your data, but it's not a frex a fixed frequency
or known ahead of time, usually seasonal is known ahead of time.
You might have a seasonal lull in sales over well, like this data here.
We seem to have a seasonal law or a lull between January and maybe March.
So we have a lull here and we have a lull here.
And that's typically.
That would be seasonal, but cyclical would be something that occurs and you can't really predict that
it's not a known frequency or duration.
Now it's a bit of a black box as to what power is actually doing, it is known that power by uses exponential
smoothing.
Now, I'm not a stats guy.
I know some statistics.
I've taken a number of statistics, statistics, classes.
I enjoy that field, but I'm not qualified to explain exponential smoothing.
But I know it has two versions of exponential smoothing, one for seasonal data and one for non seasonal
data.
Now, if you want to work through in creating this, you can there's not a whole lot to this, really
the point of this lecture is to show you how power I can use to forecast what your sales or even what
your profits might be in the next coming days, weeks or months.
But you can work through this if you want.
You can post a video, recreate this if you want to.
And if you don't, then just continue and we'll show you how we built this out and what some of this
data means.
All right, so let's take a look at this, and first, let's remove this trend line, because that's
really not the point of this discussion.
All right.
So what we have here and really this is this is trivial to set up.
And you may have worked through this.
We have a line chart where we have let's click on the line chart and we have the date he on the axis
and we have sales amount that's being plotted on a daily basis.
And then we have this this this forecasted time, serious time series period of time.
Now, to activate this, we come to.
The the analytics button and we come down to forecast and we selected a forecast.
Now, what I did was to I'm basically telling power by to go out 90 points.
Now, every point in this case is a day.
Now, if this were based on months, every point would be a month or a quarter or a year.
And then we can ignore the last some number of points.
I'm going to show you how that works.
That's kind of back forecasting.
We're going to see how that works.
And then we specify a confidence interval.
I want to explain what that is in a minute and then seasonality.
And this basically tells power.
By how far back how many data points back should I look to try to determine some level of seasonality
in the data?
All right.
Well, if we go back a year, it's going to pick up this seasonality right here.
In fact, we could actually go back.
Let's go back.
Seven hundred and thirty points and I'm going to click apply.
And now this is interesting because you can see where we're in January 2010 right here and we're forecasting
for the next three months.
And we have basically the same pattern of data that you see here and you see here.
And it picked that up because we went back far enough in time for it to analyze these er these points
in time are these data points.
And it's taking that into consideration when it's generating the predictions or the the the time values
or the data points going forward.
Now we have this concept of a confidence interval, and that's fairly important, a confidence interval
calculation takes sample data and produces a range of values that likely contains the population that
you're interested in.
OK, so we have specified a confidence level, a level of well, let's go let's go to ninety five percent
and let's see what happens.
Notice the range got larger.
OK, so when we set, for example, a ninety five percent confidence interval, that means that if you
draw 20 random samples from a sample population, you would expect 19 of the intervals to include the
population, the population value.
So the interval, this procedure, this process is useful because it produces ranges that normally contain
the value in the projected value.
Now, if you think about this.
We want to know within ninety five percent certainty where our data points are going to fall, the higher
the confidence level, then the broader that this range of values is going to be.
It has to be that way.
If we want let's say we wanted 100 percent confidence, well, we would need an upper bound of a trillion
and a lower bound of a trillion to be guaranteed that the data point, the data points are going to
fall within that range of data.
OK, that's that's an exaggeration.
But that's that's what this confidence interval does.
And if we set it down to 90, notice now that it's this range, this band is going to shrink.
And it does because we're less concerned.
We've lowered the confidence level.
And so that way it doesn't it needs less of a range to predict where the values are going to fall.
We could set this down to seventy five percent and it will shrink even more.
OK, now we've got a fairly narrow band, but we're only seventy five percent confident that these values
are going to fall within this range.
So the level at which you set your confidence level, really interval really depends on what you want
to accomplish, the type of data you're analyzing and what you feel comfortable with.
OK, and then we can set the color of the line, we can set the line style, we can set the confidence
band style right now I've got it filled, but I could I could just make out a line.
And to me, that's less useful.
I kind of like it filled in.
That gives me a better idea of what the range of values are.
So generally, confidence intervals are somewhere between 90 and ninety five percent notice.
I set it to ninety nine percent.
We've got a huge range of values here, and it really has to be that way in order to ensure that your
data points are going to fall within the range.
So let's let's let's make this 90.
That seems reasonable to me, a 90 percent interval.
And so we can be sure, for example, that this data point, if we highlight that data point, that's
forecasted to be two point two million dollars, but the upper bound is two point eight and the lower
bound is one point five.
So with a ninety five percent degree of certainty, we can say that the data point for February twenty
seven is going to be between one point five and two point nine million dollars.
How useful that is to you really depends on your situation and your business.
Now, let's talk about this ignore last number of points, this really allows us to test the model.
OK, so I've chosen to to ignore the last 90 days of the last 90 points, which is roughly the last
three months.
And so it's ignoring these data points here.
Let's focus on one of these data points.
Let's let's take that one.
Right.
Right there.
OK, so here's how to interpret this we had to ignore the last three months worth of data to test the
model.
Now look at the actual sales amount was two point six million.
The forecasted amount was two point three, roughly two point three five million.
That's actually pretty close.
And the upper bound was roughly two point seven.
And the lower bound was to OK, so.
Whether that's acceptable to you really depends upon your business, whether you find that, whether
you consider that to be an accurate forecast depends on your data, depends on your business.
I really can't tell you and I can't give you an exact number that says, OK, this is always good or
this is always not so good or this is always bad.
It really depends on your business.
But this is a nice way to go back in time a little bit to see how well your model would have done.
And for a lot of these, it looks like it looks like it's actually doing fairly well.
Here's a case where the sales amount was TUPE roughly two point three eight five and the forecast was
two point four.
That's pretty good.
That's pretty close.
So I would say it's doing a fairly good job in forecasting the data.
So in a nutshell, the Time series analysis that you're seeing here is really just an attempt to forecast
what might happen in the future.
As we said before, you know, you might want to know or have a rough idea of what you can expect tomorrow
in a week and a month or the quarter.
And, of course, it's always accurate as your past, as your past date and how predictable your past
data is.
So if your data regularly follows some sort of long term pattern, then your forecast is going to be
pretty good if you're if your data is completely random.
Your forecast is going to have very little value.