Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Probs modules are calculating negative Mutual Information #1

Open
Johnnyboycurtis opened this issue Dec 7, 2017 · 1 comment
Open

Comments

@Johnnyboycurtis
Copy link
Owner

See example:

frame
Out[8]: 
        U     V        MI
0   npreg   age  0.127532
1    skin   bmi  0.061203
2      bp   age  0.009789
3      bp   bmi  0.005360
4   npreg  skin  0.003926
5      bp  skin  0.003218
6     glu    bp  0.002185
7     glu   age  0.001108
8     glu   bmi  0.000553
9     glu  skin  0.000525
10  npreg   glu -0.000194
11   skin   age -0.000868
12  npreg    bp -0.001922
13    bmi   age -0.005869
14  npreg   bmi -0.012551
@Johnnyboycurtis
Copy link
Owner Author

Johnnyboycurtis commented Dec 7, 2017

A potential solution may be

from scipy.stats import chi2_contingency

def calc_MI(x, y, bins):
    c_xy = np.histogram2d(x, y, bins)[0]
    g, p, dof, expected = chi2_contingency(c_xy, lambda_="log-likelihood")
    mi = 0.5 * g / c_xy.sum()
    return mi

Taken from https://stackoverflow.com/questions/20491028/optimal-way-to-compute-pairwise-mutual-information-using-numpy

Another reference is:
https://en.wikipedia.org/wiki/G-test#Relation_to_Kullback–Leibler_divergence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant