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

# How to determine Spearmans correlation in Python?

This recipe helps you determine Spearmans correlation in Python

Spearman"s correlation is very important statical data that we need many times. We can calculate it manually but it takes time.

So this is the recipe on how we can determine Spearman"s correlation in Python

```
import matplotlib.pyplot as plt
import scipy.stats
import pandas as pd
import random
import seaborn as sns
```

We have imported stats, seaborn and pandas which is needed.

We have created a empty dataframe and then added rows to it with random numbers.
```
df = pd.DataFrame()
df["x"] = random.sample(range(1, 100), 75)
df["y"] = random.sample(range(1, 100), 75)
print(); print(df.head())
```

We hawe defined a function with differnt steps that we will see.

- We have calculated rank of x and y and passed it in the function scipy.stats.spearmanr().
- We have printed the result as well as the x and y values.

```
xranks = pd.Series(xs).rank()
yranks = pd.Series(ys).rank()
return scipy.stats.spearmanr(xranks, yranks)
```

```
result = spearmans_rank_correlation(df.x, df.y)[0]
print()
print("spearmans_rank_correlation is: ", result)
```

We are ploting regression plot with the fit.
```
sns.lmplot("x", "y", data=df, fit_reg=True)
plt.show()
```

x y 0 90 79 1 50 14 2 47 52 3 74 67 4 54 33 spearmans_rank_correlation is: 0.21755334281650068

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

In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

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

Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

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 machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

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

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

The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.