scientific_comp_projects/CODE/[python]machine_learning/[real_python]statistics/correlation_numpy.ipy

23 lines
689 B
Plaintext

# coding: utf-8
import numpy as np
x = np.arange(10,20)
x
y = np.array([2,1,4,5,8,12,18,25,96,48])
y
r = np.corrcoef(x,y)
r
import scipy.stats
import scipy.stats as ss
r = np.corrcoef(x,y) # returns the correlation matrix
ss.pearsonr(x,y) # Pearson's r
ss.spearmanr(x,y) # Spearman's rho
ss.kendalltau(x,y) # Kendall's tau
ss.kendalltau(x,y).correlation # Kendall's tau correlation
ss.kendalltau(x,y).correlation # Kendall's tau correlation(using the dot notation)
ss.kendalltau(x,y).[0] # Kendall's tau correlation(using the indices)
ss.kendalltau(x,y)[0] # Kendall's tau correlation(using the indices)
import pandas as pd
x = pd.Series(range(10,20))
x
%save -r correlation_numpy 1-99999