Course Content

# Time Series Analysis

1. Time Series: Let's Start

2. Time Series Processing

3. Time Series Visualization

Time Series Analysis

## Decomposition

Decomposition is a time series analysis technique that allows you to decompose a series into several components: seasonality, noise, and trends.

Let's take supermarket sales as an example.

Speaking of seasonality, sales have daily seasonality (the number of purchases increases in the evening and may be less in the morning), weekly seasonality (most purchases are made on Fridays and weekends), and monthly seasonality (for example, more purchases are made during the holiday months: December, January).

Let's shed some light on the mathematical model of the decomposition method:

As we can see, the coefficients `T`, `S`, and `R` are responsible for each parameter.

You can see the main difference between trend and seasonality below:

While a trend is a general systematic linear or non-linear component, a seasonal component is recurring. Both of these types of components can be present in the time series at the same time.

To run the decomposition method, we will use the MSTL method, which stands for Multiple Seasonal-Trend decomposition using Loess. Import `statsmodel` to run time series decomposition:

As a result, we have the following:

With the help of this visualization, we can already track the overall upward trend and seasonality. In the general case, decomposition can help us move from the analysis of a non-stationary series to a stationary one, excluding the seasonal component and the trend, we can analyze the series using residuals.

Everything was clear?

Section 2. Chapter 4