Skip to content

Instantly share code, notes, and snippets.

@adelavega
Last active December 26, 2015 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adelavega/7190476 to your computer and use it in GitHub Desktop.
Save adelavega/7190476 to your computer and use it in GitHub Desktop.
Distance correlation matrix
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