Last active
December 26, 2015 17:58
-
-
Save adelavega/7190476 to your computer and use it in GitHub Desktop.
Distance correlation matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dcor_matrix(data): | |
"""Creates a correlation matrix using the dcor (distance correlation) function based on the R (energy) implementation | |
Assumes that variables are columns | |
Input: | |
data - x by y np array where y is the number of variables | |
Output: | |
Returns a correlation matrix as a np array of shape y by y | |
""" | |
import numpy as np | |
import dcor_py # Requires dcor implementation by Andrew Yates in same folder | |
return [1 if c1==c2 else dcor_py.dcor(column1, column2) for c1, column1 in enumerate(data.T0) for c2, column2 in enumerate(data.T)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment