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

wrong input into entropy function #14497

Closed
minhsphuc12 opened this issue Jul 28, 2019 · 11 comments
Closed

wrong input into entropy function #14497

minhsphuc12 opened this issue Jul 28, 2019 · 11 comments

Comments

@minhsphuc12
Copy link

h_true, h_pred = entropy(labels_true), entropy(labels_pred)

entropy must be inputed with frequency table of labels_true / labels_pred, not those array directly.
Example solution

from collections import Counter
freq_table = [x[1] for x in dict(Counter(labels_true)).items()]
entropy(freq_table)
@vasujogani
Copy link

working on it

@jnothman
Copy link
Member

jnothman commented Jul 28, 2019 via email

@vasujogani
Copy link

I think you might be right. I just saw entropy using np.unique which I believe would take care of the issue

@minhsphuc12
Copy link
Author

Please consider example
vec_a = np.asarray([0, 1, 2, 0, 3, 4, 5, 1])
stats.entropy(vec_a) #1.6304325826288886

from collections import Counter
freq_table = [x[1] for x in dict(Counter(vec_a)).items()]
stats.entropy(freq_table) #1.7328679513998633

As you can see, vec_a is cluster vector, does not has same length as freq_table.

The issue here is not normalizing the input (same length), but rather using cluster vector, instead of using frequency table as input.

@jnothman
Copy link
Member

jnothman commented Jul 29, 2019 via email

@minhsphuc12
Copy link
Author

minhsphuc12 commented Jul 29, 2019 via email

@jnothman
Copy link
Member

jnothman commented Jul 29, 2019 via email

@minhsphuc12
Copy link
Author

Thanks problem solved. Root cause is I do not aware that averaging method used in my sklearn version is ‘max’, instead of ‘arithmetic’ of 0.22.

@minhsphuc12
Copy link
Author

Although we would need to update the documentation example.
image

@thomasjpfan
Copy link
Member

How would you want to update the example?

@cmarmo
Copy link
Member

cmarmo commented Mar 23, 2022

Closing this one as it is quite old, the main issue has been solved and there was no answer to the last question.
Feel free to reopen if things can be clarified.

@cmarmo cmarmo closed this as completed Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants