1 00:00:00,510 --> 00:00:06,210 In this video, we will learn how to decompose time series data using Python 2 00:00:09,110 --> 00:00:10,290 in order to Reflektor. 3 00:00:10,530 --> 00:00:19,320 We have discussed that we can create a time series data as a combination of four different parts. 4 00:00:20,070 --> 00:00:29,540 Level grained seasonality and noise level is the average value in the cities trend. 5 00:00:29,730 --> 00:00:33,680 Is that increasing or decreasing value in the cities? 6 00:00:35,100 --> 00:00:41,300 Seasonality is the repeating short term cycle in the cities and noise is the random variation in those 7 00:00:41,310 --> 00:00:41,830 cities. 8 00:00:44,910 --> 00:00:50,660 Now there are two ways to combine these four parts to create a time series data. 9 00:00:50,880 --> 00:00:59,640 First is the additive model in which we treat our Time series data as a sum of these four components 10 00:00:59,720 --> 00:01:02,130 leveret crane seasonality and noise. 11 00:01:03,660 --> 00:01:10,860 The second way is the multiplicative model in which we assume that our Time series is the multiplication 12 00:01:10,860 --> 00:01:13,200 of all these four different parts. 13 00:01:14,940 --> 00:01:20,750 Now, it would be great if we can identify these four components from our series. 14 00:01:22,050 --> 00:01:25,860 It will help us in better understanding over time cities. 15 00:01:27,060 --> 00:01:34,410 And it will also help to perform different types of preprocessing for all this, for different parts 16 00:01:34,410 --> 00:01:35,340 of their time cities. 17 00:01:36,840 --> 00:01:44,400 So now let's learn how to decompose our time cities data in these four different parts. 18 00:01:47,540 --> 00:01:53,080 Now, decomposing time cities in these four different parts is very easy in Britain. 19 00:01:54,500 --> 00:02:01,520 There are premade functions available in libraries such as steak murder to barbarically decompose time 20 00:02:01,520 --> 00:02:03,860 cities using just a single come on. 21 00:02:06,800 --> 00:02:08,330 So let's take an example. 22 00:02:09,200 --> 00:02:13,040 We will be using the same data that tells us U.S. airline data. 23 00:02:13,800 --> 00:02:17,600 And and this time we are saving it in our data frame. 24 00:02:17,730 --> 00:02:21,450 Miles Beacom, underscore D.F.. 25 00:02:22,700 --> 00:02:23,950 Now, let's run this. 26 00:02:23,960 --> 00:02:24,290 Come on. 27 00:02:27,940 --> 00:02:33,770 And now let's also change the index of, what, minus two duffing? 28 00:02:34,970 --> 00:02:37,860 So before that, let's have a look. 29 00:02:40,800 --> 00:02:43,580 And the first five values of this stuffing. 30 00:02:48,770 --> 00:02:54,800 You can see we have the money in our first column which contained the beat data. 31 00:02:55,730 --> 00:03:00,460 The second column here is Mines M-m, which contain the value of data frame. 32 00:03:01,640 --> 00:03:08,040 And you can also see the indexes are numeric starting from zero. 33 00:03:10,430 --> 00:03:13,760 Not to use premade functions and liabilities. 34 00:03:13,850 --> 00:03:18,230 We have to convert our data frame in that data frame. 35 00:03:18,410 --> 00:03:21,290 Their indexes are in the form of data. 36 00:03:22,130 --> 00:03:28,420 So that's why we are changing indexes of our data frame from numeric to beat format. 37 00:03:28,790 --> 00:03:29,960 So let's run this. 38 00:03:31,780 --> 00:03:36,320 This index we are using is minus the com d.f. dot index. 39 00:03:36,650 --> 00:03:38,420 So we are referring to index. 40 00:03:38,780 --> 00:03:44,600 And then we are basically saving what month data in place of this index value. 41 00:03:45,520 --> 00:03:46,340 That stand this. 42 00:03:46,380 --> 00:03:48,930 Let's look at the first five values again. 43 00:03:49,760 --> 00:03:56,780 So you can see now the indexes are in the form on dates and set of numeric. 44 00:04:00,530 --> 00:04:09,710 Now we're going to use seasonally decompose function from such small liability to directly get these 45 00:04:09,710 --> 00:04:12,240 components from our data cities. 46 00:04:12,860 --> 00:04:17,960 So let's import seasonally decompose function from a search model first. 47 00:04:19,160 --> 00:04:21,590 And to use this function. 48 00:04:21,710 --> 00:04:24,380 We need to provide two parameters. 49 00:04:25,190 --> 00:04:29,170 First, we have to grow in the cities which contains our values. 50 00:04:29,750 --> 00:04:37,010 And in the second parameter, we have to provide whether we want to use an additive model or make duplicate 51 00:04:37,010 --> 00:04:37,460 a model. 52 00:04:40,250 --> 00:04:45,780 So we are creating another variable result which is going to contain the result of this function. 53 00:04:46,430 --> 00:04:54,210 We are using seasonally compose and as a series we are providing our minus data from this Dufresne. 54 00:04:54,860 --> 00:05:02,870 So we are mentioning our data, Femia, and the column which contains the values of Forward Time series 55 00:05:02,870 --> 00:05:03,140 data. 56 00:05:03,530 --> 00:05:10,760 So we are mentioning models decompose, SBF and minus M-m and first we are going to use an additive 57 00:05:10,760 --> 00:05:11,120 model. 58 00:05:11,300 --> 00:05:14,170 So that's why we are writing more than we do additive. 59 00:05:15,170 --> 00:05:16,100 Let's run this. 60 00:05:18,790 --> 00:05:20,780 Now our result object is ready. 61 00:05:20,930 --> 00:05:30,260 We can Derek lead right with a dot plot to get the values of seasonality, train and noise, et cetera. 62 00:05:30,570 --> 00:05:31,940 So let's run this. 63 00:05:36,040 --> 00:05:40,100 So you can see we are getting four different line checks. 64 00:05:41,040 --> 00:05:42,550 First is the observed. 65 00:05:43,570 --> 00:05:46,590 This is the line chart of over what is not data cities. 66 00:05:49,120 --> 00:05:51,400 The second line chart is off trends. 67 00:05:52,330 --> 00:05:59,410 This line chart give us the trend values after removing noise and seasonality from our data. 68 00:06:02,110 --> 00:06:03,810 The next is the seasonal line. 69 00:06:03,830 --> 00:06:08,480 Check this line chart will give us the seasonality trend in our data. 70 00:06:11,220 --> 00:06:19,020 The next line chart is of the reservation values that are remaining after incorporating trend and seasonality. 71 00:06:22,430 --> 00:06:28,010 One thing to note here is that you have to look at y axis as well. 72 00:06:28,700 --> 00:06:34,160 So for the first group, the Y axis is between zero to four Pinto's and train. 73 00:06:34,250 --> 00:06:39,230 The Y axis is between zero to 12500 and fourth seasonality. 74 00:06:39,290 --> 00:06:44,290 The Y axis labels are between minus two tosing to 2000. 75 00:06:44,990 --> 00:06:51,680 So we can see that the seasonality variation in our data is from minus two poles on unit two plus two 76 00:06:51,680 --> 00:06:52,350 thousand unit. 77 00:06:53,720 --> 00:07:01,100 So don't just look at the graphs, look at the scale of your y axis as well to better understand the 78 00:07:01,100 --> 00:07:01,610 city's. 79 00:07:04,270 --> 00:07:10,600 Now let's learn how to decompose data, cities using them multiplicative more than so earlier. 80 00:07:10,840 --> 00:07:16,480 While using a great deal more than we were giving model equal to a relative as one of the argument. 81 00:07:19,420 --> 00:07:26,890 To be composed using multiplicative more than we have to give than equal to multiplicative instead of 82 00:07:26,950 --> 00:07:28,520 additive as an outcome. 83 00:07:30,100 --> 00:07:34,060 So this time we are saving our reserves and to reserve, too. 84 00:07:34,630 --> 00:07:37,350 And we are using the same functions seasonally decompose. 85 00:07:37,450 --> 00:07:44,870 We are mentioning the column where we have our values, which is mights decompose, D.F. and minus cement. 86 00:07:45,580 --> 00:07:48,140 And this time we are going to use multiplicative more. 87 00:07:49,720 --> 00:07:51,600 So let's run this on. 88 00:07:51,910 --> 00:07:55,910 Let's again load this new desert of multiplicative model. 89 00:08:00,350 --> 00:08:04,780 So this is the result we are getting in the first line, Chad. 90 00:08:05,120 --> 00:08:10,410 We have to observe the values of what the densities and the second target. 91 00:08:11,750 --> 00:08:13,940 We have the trained values and the code. 92 00:08:14,240 --> 00:08:15,950 We have the seasonality variation. 93 00:08:16,370 --> 00:08:19,400 And in the fourth chart, we have that as a real value. 94 00:08:20,390 --> 00:08:22,850 Again, look at why it is as well. 95 00:08:23,930 --> 00:08:26,360 So you can see that for seasonality. 96 00:08:26,770 --> 00:08:30,800 A word is what varies from point eight to one point two. 97 00:08:31,940 --> 00:08:34,950 That's because we are using multiplicative model here. 98 00:08:35,900 --> 00:08:40,010 So for additive seasonality, we were adding seasonality value. 99 00:08:40,040 --> 00:08:42,920 That's why we were getting minus 2000 to 2000. 100 00:08:43,850 --> 00:08:46,460 But here we are multiplying the seasonality. 101 00:08:47,120 --> 00:08:50,540 So point eight means we are reducing the value of whity. 102 00:08:50,960 --> 00:08:56,840 And one point two means we are increasing the value of whity by 20 percent. 103 00:08:59,960 --> 00:09:01,410 So it ended in murder. 104 00:09:01,970 --> 00:09:10,310 We were using absolute value to add on, but in my typical day model, we are multiplying that value 105 00:09:10,550 --> 00:09:11,390 with our data. 106 00:09:11,420 --> 00:09:16,490 That's why the seasonality value lies between point eight to one point. 107 00:09:18,950 --> 00:09:27,050 Now, this is a very easy way to analyze whether your data have Grendon seasonality in it or not. 108 00:09:27,650 --> 00:09:31,220 So just use seasonally decompose function from its search. 109 00:09:31,230 --> 00:09:37,640 Smardon to analyze your data cities and identify the tendencies, the literary pattern in your data. 110 00:09:39,020 --> 00:09:40,190 That's all for this lecture. 111 00:09:40,340 --> 00:09:40,820 Thank you.