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
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
python calculate correlation
# For a measure the strength of association between two variables;
import numpy as np
from scipy.stats import spearmanr, pearsonr, kendalltau
serie1 = np.array([-2, -1, 0, 1, 4])
serie2 = np.array([-2.5, -.75, 1, 2, 6])
# linear ==> Pearson
pearsonr(serie1, serie2)
pearsonrResult(correlation=0.9964803994464919, pvalue=0.0002505212149642603)
# Non-linear ==> Spearman or kendall
spearmanr(serie1, serie2)
SpearmanrResult(correlation=0.9999999999999999, pvalue=1.4042654220543672e-24)
kendalltau(serie1, serie2)
KendalltauResult(correlation=0.9999999999999999, pvalue=0.016666666666666666)
correlation python
import numpy as np
import scipy.stats
x = np.arange(15, 20)
y = np.arange(5, 10)
stat, p = scipy.stats.pearsonr(x, y)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us