Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

correlation matrix python

import seaborn as sns
df = sns.load_dataset('iris')
corr_matrix = df.corr()
corr_matrix.style.background_gradient(cmap='coolwarm')
# 'RdBu_r', 'BrBG_r', & PuOr_r are other good diverging colormaps
Comment

correlation matrix python

# option 1
corr_matrix = df.corr()
corr_matrix.style.background_gradient(cmap='coolwarm')

# option 2
plt.figure(figsize=(10,10))
cor = df.corr()
sns.heatmap(cor, annot=True, cmap=plt.cm.Blues)
Comment

python Correlation matrix of features

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

file = 'https://aegis4048.github.io/downloads/notebooks/sample_data/unconv_MV_v5.csv'
df = pd.read_csv(file)

df = df.iloc[:, 1:-1]

corr = df.corr(method='spearman')

# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

# Set up the matplotlib figure
fig, ax = plt.subplots(figsize=(6, 5))

# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True, sep=100)

# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, cmap=cmap, vmin=-1, vmax=1, center=0, linewidths=.5)

fig.suptitle('Correlation matrix of features', fontsize=15)
ax.text(0.77, 0.2, 'aegis4048.github.io', fontsize=13, ha='center', va='center',
         transform=ax.transAxes, color='grey', alpha=0.5)

fig.tight_layout()
Comment

PREVIOUS NEXT
Code Example
Python :: change django time zone 
Python :: Python NumPy swapaxis Function Syntax 
Python :: knowing the sum null values in a specific row in pandas dataframe 
Python :: changing plot background color in python 
Python :: python dict remove key 
Python :: youtube-dl python get file name 
Python :: django models.py convert DateTimeField to DateField 
Python :: python list unique in order 
Python :: how to do disconnect command on member in discord python 
Python :: custom keyboard telegram bot python 
Python :: how to check libraries in python 
Python :: delete migrations django and start over deployment heroku 
Python :: django admin.py all fields 
Python :: how to delete a variable python 
Python :: making lists with loops in one line python 
Python :: import qq plot 
Python :: jpython 
Python :: string formatting in python 
Python :: mss python install 
Python :: pythn programme for adding user unputs 
Python :: when button is clicked tkinter python 
Python :: isntall packages to databricks 
Python :: create django group 
Python :: how to make a list using lambda function in python 
Python :: pandas profile report python 
Python :: count list python 
Python :: insert data in table python 
Python :: count repeated characters in a string python 
Python :: loop throughthe key and the values of a dict in python 
Python :: calculate distance in python 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =