Get startedGet started for free

Seasonality and trends

1. Seasonality and trends

Let's now have a look at some key-properties of time-series. This is an important point for IoT Data, since most IoT datasets are also timeseries.

2. Time series components

Some of the key properties of time series data are trend, seasonality and noise. Seasonality describes a clear periodic pattern in the data. Trend describes if the time series is decreasing or increasing constantly, and residual, sometimes also called noise, is the unexplained variance in the data. Based on this, we can use the following formula: The Series at time-point t is the sum of trend, seasonal and residual at time-point t. For example, we observed a temperature of 20-point-2 degrees at 10am. The determined trend at this point is 14-point-9, seasonality is 4-point-39 and the noise is 0-point-91. The sum of these components needs to equal 20-point-2, the observed temperature.

3. Seasonal decompose

You probably have noticed some clear patterns in the data used throughout this course. We can rely on statsmodels' seasonal_decompose(), which automates this analysis for us. We first import statsmodels-dot-api as sm. We then run sm-dot-tsa-dot-seasonal_decompose() on the column we're most interested in. The result has each of the components assigned as attributes. We can print the head of the seasonal part by running decomp-dot-seasonal-dot-head(). We visualize the result by using dot-plot() on the result.

4. Seasonal decompose

The resulting plot contains four subplots. The first is the observed series, which is the series we passed in, and the other subplots are each Trend, Seasonal, and Residual, or Noise. This allows us to compare the different components of the time-series with each other. On the x axis, we have the time, which is aligned between all subplots. The y axis contains the absolute values for the different time-series components.

5. Combined plot

We can also combine the plots into one. We first plot the time-series, before then adding the trend and seasonality of temperature to the same plot. We can access this via the decomposition variable decomp-dot-trend and decomp-dot-seasonal. Notice that we need to specify the "temperature" column for the trend and seasonality calculation. Since the DataFrame has multiple columns, we need to specify which column should be used.

6. Combined plot

The advantage of this plot method is that we can leave out certain parts like noise, and customize the plot further with annotations or additional lines.

7. Let's practice!

And now, let's practice.