Apurva Patil — Published On January 6, 2021 and Last Modified On January 11th, 2021
Beginner Python Statistics Structured Data Technique

This article was published as a part of the Data Science Blogathon.


When we try to infer something from what we have heard or read, the first step we do is relate a few of the parameters or scenes, etc. with each other and then proceed. Correlation means to find out the association between the two variables and Correlation coefficients are used to find out how strong the is relationship between the two variables. The most popular correlation coefficient is Pearson’s Correlation Coefficient. It is very commonly used in linear regression.

Consider the example of car price detection where we have to detect the price considering all the variables that affect the price of the car such as carlength, curbweight, carheight, carwidth, fueltype, carbody, horsepower, etc.

Correlation can be found out between continuous variables using python:

Pearson’s Correlation Coefficient plot check
Pearson’s Correlation Coefficient graph

We can see in the above scatterplot, as the carlength, curbweight, carwidth increases price of the car also increases. So, we can say that there is a positive correlation between the above three variables with car price. Here, we also see that there is no correlation between the carheight and car price.

Pearson’s Correlation Coefficient milage scatterplot

Cars with high prices have very low mileage as compared to the low range of cars. Hence, in this case, we can say that there is a negative correlation between car price and mileage.



Let’s focus on some statistical explanation of it. Pearson’s Correlation coefficient is represented as ‘r’, it measures how strong is the linear association between two continuous variables using the formula:

Pearson’s Correlation Coefficient formula

Values of Pearson’s Correlation are:

Value of ‘r’ ranges from ‘-1’ to ‘+1’. Value ‘0’ specifies that there is no relation between the two variables. A value greater than ‘0’ indicates a positive relationship between two variables where an increase in the value of one variable increases the value of another variable. Value less than ‘0’ indicates a negative relationship between two variables where an increase in the value of one decreases the value of another variable.


types of correlation

Pearson correlation attempts to draw a line of best fit through the spread of two variables. Hence, it specifies how far away all these data points are from the line of best fit. Value of ‘r’ equal to near to +1 or -1 that means all the data points are included on or near to the line of best fit respectively. Value of ‘r’ closer to the ‘0’ data points is around the line of best fit.

Considering the same example of the car price, let’s find out the ‘r’ value using ‘pearsonr’ function in python.

As stated earlier, the value of Pearson correlation for Price vs Curbweight is 0.835 and as there is no correlation between Price and Carheight, hence the Pearson Correlation value between Price & Carheight is near to 0 which is 0.12.


Assumptions for a Pearson Correlation:

1. Data should be derived from random or least representative samples, draw a meaningful statistical inference.

2. Both variables should be continuous and normally distributed.

3. There should be Homoscedasticity, which means the variance around the line of best fit should be similar.

4. Extreme outliers influence the Pearson Correlation Coefficient. You need to consider outliers that are unusual only on one variable, called as ‘univariate variable’ or for both of the variables known as ‘multivariate outliers’. 2 variables are measured independently from each other pairs. e.g. If we plot age vs amount then, we can certainly, see that there is a correlation between the age of a person and loan the amount is given to that person, as age increases the loan amount given to the

python code

person decreases and vice versa. But if we plot the loan amount vs age, it is not possible to draw any conclusion from it. It would violate the assumption.



1. https://www.statisticshowto.com/probability-and-statistics/correlation-coefficient-formula/


3. http://learntech.uwe.ac.uk/da/default.aspx?pageid=1442


About the Author

Apurva Patil

Our Top Authors

Download Analytics Vidhya App for the Latest blog/Article

Leave a Reply Your email address will not be published. Required fields are marked *