How to compare 2 time series data points using Grangers test?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

# How to compare 2 time series data points using Grangers test?

This recipe helps you compare 2 time series data points using Grangers test

0

## Recipe Objective

How to compare 2 time series data points using Grangers test?

Granger relation check is employed to see if just once series is going to be helpful to forecast another variable by investigation relation between 2 variables in a very statistic. The strategy could be a probabilistic account of causality; it uses discovered knowledge sets to search out patterns of correlation. One smart issue regarding statistic vector auto regression (VAR) is that we have a tendency to check ‘causality’ in some sense.

How Granger Causality works:

It is supported the concept that if X causes Y, then the forecast of Y supported previous values of Y and also the previous values of X ought to the best lead to the forecast of Y supported previous values of Y alone. Granger relation shouldn't be accustomed check if a lag of Y causes Y. Instead, it's typically used on exogenous (not Y lag) variables solely. In easy terms ‘X is alleged to Granger-cause Y if Y is higher expected victimization the histories of each X and Y than it will by using the history of Y alone.

Assumtions we made while performing Granger Causality Test:- 1. Future values cannot cause the past values. 2. A notably distinct data is contained in cause regarding impact which is able to not be accessible elsewhere

## Step 1- Importing Library.

We will import all the Libraries including grangercausalitytests.

``` from statsmodels.tsa.stattools import grangercausalitytests import pandas as pd import numpy as np ```

## Step 2- Reading California house Dataset.

``` df = pd.read_csv("/content/sample_data/california_housing_train.csv") df.head() ```

## Step 3- Applying Granger Causality Test.

This test is a X/Y based test. We have to feed two columns thorugh this test.

``` res = grangercausalitytests(df[['median_income', 'median_house_value']], maxlag=4)```

#### Relevant Projects

##### German Credit Dataset Analysis to Classify Loan Applications
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.

##### Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

##### Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

##### NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

##### Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

##### Build a Similar Images Finder with Python, Keras, and Tensorflow
Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

##### Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

##### Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

##### Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

##### Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.