In this section, we are going to cover moving average smoothly.
You got a glimpse of this when we saw the window type features in the feature engineering lecture.
Now, we will cover this in a more structured format.
So we will cover these three things first.
What is moving average and why we do it?
Then we will see these two types of moving averages centered, window moving average and grilling window
moving average.
Lastly, we will see how moving average is used for feature engineering and how it is used, what prediction
purposes.
So let's start.
Moving out, it's moving is simply creating a new series where the values are averages of the draw observations
in the original time cities.
Let us see an example to understand this here.
I have Monterey's average temperature data in the month of January.
We had average temperature of 39 degrees Fahrenheit.
In fact, it was 42 in the month of March.
It was 50 degrees Fahrenheit.
Now, in March, we can find out the average of last three months.
The average temperature of last three months would be 44 degrees Fahrenheit.
We can do this for other months.
And this is also true.
If we have April, we can find the average of February, March and April.
In the month of May, we can average the of March, April and May.
This value comes out to be sixty in this way.
We are averaging the last three values of temperature and creating a new series.
The three values which we are averaging are moving along the cities as we are moving forward in the
cities and the new cities that we get by finding the average of last few months is the new moving average
cities.
But why did we do this?
Let's compare a graph of raw observations and moving averages.
Here you can see that the moving average graph of stock prices is more smooth.
Then the raw data.
It does remove defined green variations between timestamps.
Our agenda.
In doing so is that in this process, we are trying to remove the noise and trying to find the underlying
process.
So you can see in this graph, by averaging out devalues our stock price.
We have identified this underlying process in these stock prices.
Now, in not monthly temperature data, for example, we were averaging last three values, these three
values constitute that window in which we do the averaging.
And this window is moon.
As we move along this series, this window has two parameters that we need to fix before we start doing
moving average modeling.
The first parameter is the window bit.
That is the number of values that we want to average over here.
The window.
It is three because we are averaging three values.
If you want to average last five values window, it becomes five.
The second part of me that is very you want to position this window.
So right now, at the third observation, we position this window so that we average the last three
values.
That is we are averaging the first, second and third value to get the moving average value for third
observation.
So for them, month of March, we got the moving average value of 44.
By averaging temperature values for January, February and March.
This is called really moving average.
On the other hand, if you please, the window in such a way that the current timestep is at its center,
that will be called centered moving average.
So if we find the average of Jan FIB and March and a sign that moving average value to decentered value,
which is February, then this is called centered moving average.
But as you can note, that for centered moving average.
You need to know the next value of the future value.
Already.
And since and discourse, we are trying to predict those future values.
We will not be using these standard moving average.
Now, trailing, moving average can be used in two ways.
One is feature engineering and the other is forecasting.
The context behind both is simple.
If you want to forecast the city's value at time C, D, D, you can use the average value of the previous
few time cities.
If you use these average values as a new feature, then it is feature engineering.
On the other hand, you can simply assign this average value also as the forecasted value for time P
plus one.
So, for example, if you want to forecast for the month of June, you can simply use this moving average
value.
That is sixty has the forecasted value for the month of June.
Of course, this is a very simple and a naive method of forecasting, and it assumes that there is no
trend and seasonality in the data.
So in terms of accuracy, this method does not perform very well.
But in terms of its simplicity and the ease of implementation, it is often preferred to get a rough
estimate of future values using the moving average method.
So that's all the duty we need to know in this particular session.
We will find out how to get billing values and how we use those trailing values as a new feature.