DATA MUNGING
DATA CLEANING PYTHON
MACHINE LEARNING RECIPES
PANDAS CHEATSHEET
ALL TAGS
# How to determine Pearsons correlation in Python?

# How to determine Pearsons correlation in Python?

This recipe helps you determine Pearsons correlation in Python

In [2]:

```
def Snippet_120():
print()
print(format('How to determine Pearson\'s correlation in Python','*^82'))
import warnings
warnings.filterwarnings("ignore")
# load libraries
import matplotlib.pyplot as plt
import statistics as stats
import pandas as pd
import random
import seaborn as sns
# Create empty dataframe
df = pd.DataFrame()
# Add columns
df['x'] = random.sample(range(1, 100), 75)
df['y'] = random.sample(range(1, 100), 75)
# View first few rows of data
print(); print(df.head())
# Calculate Pearsonâ€™s Correlation Coefficient
def pearson(x,y):
# Create n, the number of observations in the data
n = len(x)
# Create lists to store the standard scores
standard_score_x = []; standard_score_y = [];
# Calculate the mean of x
mean_x = stats.mean(x)
# Calculate the standard deviation of x
standard_deviation_x = stats.stdev(x)
# Calculate the mean of y
mean_y = stats.mean(y)
# Calculate the standard deviation of y
standard_deviation_y = stats.stdev(y)
# For each observation in x
for observation in x:
# Calculate the standard score of x
standard_score_x.append((observation - mean_x)/standard_deviation_x)
# For each observation in y
for observation in y:
# Calculate the standard score of y
standard_score_y.append((observation - mean_y)/standard_deviation_y)
# Multiple the standard scores together, sum them, then divide by n-1, return that value
return (sum([i*j for i,j in zip(standard_score_x, standard_score_y)]))/(n-1)
# Show Pearson's Correlation Coefficient
result = pearson(df.x, df.y)
print()
print("Pearson\'s correlation coefficient is: ", result)
sns.lmplot('x', 'y', data=df, fit_reg=True)
plt.show()
Snippet_120()
```

In [ ]:

```
```

In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

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

In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

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.

In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.