MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# How to decompose a time series?

# How to decompose a time series?

This recipe helps you decompose a time series

Time series decomposition involves thinking of a series as a combination of level, trend, seasonality, and noise components.

So this recipe is a short example on how to decompose a time series. Let's get started.

```
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.seasonal import seasonal_decompose
```

Let's pause and look at these imports. Numpy and pandas are general ones. Here matplotlib.pyplot will help us in plotting. statsmodels.tsa.seasonal comes handy while analysing patterns.

```
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date']).set_index('date')
```

Here, we have used one time series data from github. Also, we have set our index to date.

Now our dataset is ready.

```
result = seasonal_decompose(df, model='additive')
```

We have simply created an object of seasonal_decompose to understand our model with additive feature.

```
print(result.trend)
print(result.seasonal)
print(result.resid)
print(result.observed)
```

We are priting the decomposition of our dataset in here

```
result.plot()
plt.show()
```

Finally, we have tried to visualize trends in one go.

Once we run the above code snippet, we will see:

Scroll down the ipython file to visualize the output.

Given big data at taxi service (ride-hailing) i.e. OLA, you will learn multi-step time series forecasting and clustering with Mini-Batch K-means Algorithm on geospatial data to predict future ride requests for a particular region at a given time.

Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Use the Adult Income dataset to predict whether income exceeds 50K yr based on
census data.

In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.