In this video, we will learn how to decompose time series data using Python
in order to Reflektor.
We have discussed that we can create a time series data as a combination of four different parts.
Level grained seasonality and noise level is the average value in the cities trend.
Is that increasing or decreasing value in the cities?
Seasonality is the repeating short term cycle in the cities and noise is the random variation in those
cities.
Now there are two ways to combine these four parts to create a time series data.
First is the additive model in which we treat our Time series data as a sum of these four components
leveret crane seasonality and noise.
The second way is the multiplicative model in which we assume that our Time series is the multiplication
of all these four different parts.
Now, it would be great if we can identify these four components from our series.
It will help us in better understanding over time cities.
And it will also help to perform different types of preprocessing for all this, for different parts
of their time cities.
So now let's learn how to decompose our time cities data in these four different parts.
Now, decomposing time cities in these four different parts is very easy in Britain.
There are premade functions available in libraries such as steak murder to barbarically decompose time
cities using just a single come on.
So let's take an example.
We will be using the same data that tells us U.S. airline data.
And and this time we are saving it in our data frame.
Miles Beacom, underscore D.F..
Now, let's run this.
Come on.
And now let's also change the index of, what, minus two duffing?
So before that, let's have a look.
And the first five values of this stuffing.
You can see we have the money in our first column which contained the beat data.
The second column here is Mines M-m, which contain the value of data frame.
And you can also see the indexes are numeric starting from zero.
Not to use premade functions and liabilities.
We have to convert our data frame in that data frame.
Their indexes are in the form of data.
So that's why we are changing indexes of our data frame from numeric to beat format.
So let's run this.
This index we are using is minus the com d.f. dot index.
So we are referring to index.
And then we are basically saving what month data in place of this index value.
That stand this.
Let's look at the first five values again.
So you can see now the indexes are in the form on dates and set of numeric.
Now we're going to use seasonally decompose function from such small liability to directly get these
components from our data cities.
So let's import seasonally decompose function from a search model first.
And to use this function.
We need to provide two parameters.
First, we have to grow in the cities which contains our values.
And in the second parameter, we have to provide whether we want to use an additive model or make duplicate
a model.
So we are creating another variable result which is going to contain the result of this function.
We are using seasonally compose and as a series we are providing our minus data from this Dufresne.
So we are mentioning our data, Femia, and the column which contains the values of Forward Time series
data.
So we are mentioning models decompose, SBF and minus M-m and first we are going to use an additive
model.
So that's why we are writing more than we do additive.
Let's run this.
Now our result object is ready.
We can Derek lead right with a dot plot to get the values of seasonality, train and noise, et cetera.
So let's run this.
So you can see we are getting four different line checks.
First is the observed.
This is the line chart of over what is not data cities.
The second line chart is off trends.
This line chart give us the trend values after removing noise and seasonality from our data.
The next is the seasonal line.
Check this line chart will give us the seasonality trend in our data.
The next line chart is of the reservation values that are remaining after incorporating trend and seasonality.
One thing to note here is that you have to look at y axis as well.
So for the first group, the Y axis is between zero to four Pinto's and train.
The Y axis is between zero to 12500 and fourth seasonality.
The Y axis labels are between minus two tosing to 2000.
So we can see that the seasonality variation in our data is from minus two poles on unit two plus two
thousand unit.
So don't just look at the graphs, look at the scale of your y axis as well to better understand the
city's.
Now let's learn how to decompose data, cities using them multiplicative more than so earlier.
While using a great deal more than we were giving model equal to a relative as one of the argument.
To be composed using multiplicative more than we have to give than equal to multiplicative instead of
additive as an outcome.
So this time we are saving our reserves and to reserve, too.
And we are using the same functions seasonally decompose.
We are mentioning the column where we have our values, which is mights decompose, D.F. and minus cement.
And this time we are going to use multiplicative more.
So let's run this on.
Let's again load this new desert of multiplicative model.
So this is the result we are getting in the first line, Chad.
We have to observe the values of what the densities and the second target.
We have the trained values and the code.
We have the seasonality variation.
And in the fourth chart, we have that as a real value.
Again, look at why it is as well.
So you can see that for seasonality.
A word is what varies from point eight to one point two.
That's because we are using multiplicative model here.
So for additive seasonality, we were adding seasonality value.
That's why we were getting minus 2000 to 2000.
But here we are multiplying the seasonality.
So point eight means we are reducing the value of whity.
And one point two means we are increasing the value of whity by 20 percent.
So it ended in murder.
We were using absolute value to add on, but in my typical day model, we are multiplying that value
with our data.
That's why the seasonality value lies between point eight to one point.
Now, this is a very easy way to analyze whether your data have Grendon seasonality in it or not.
So just use seasonally decompose function from its search.
Smardon to analyze your data cities and identify the tendencies, the literary pattern in your data.
That's all for this lecture.
Thank you.