Created
June 27, 2013 14:40
-
-
Save chrisgorgo/5876972 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 partial_correlation_via_inverse(X): | |
model = GraphLassoCV() | |
model.fit(X) | |
prec_ = model.precision_ | |
return -cov2corr( model.precision_ ) ) | |
def cov2corr( A ): | |
""" | |
covariance matrix to correlation matrix. | |
""" | |
d = np.sqrt(A.diagonal()) | |
A = ((A.T/d).T)/d | |
return A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this looks good.