Permalink
Browse files

ENH simplified entropy calculation

  • Loading branch information...
1 parent c7d5293 commit a97e6c8010f67e8b4e30950d1aae21d6e8e3d81c @amueller amueller committed May 5, 2012
Showing with 1 addition and 2 deletions.
  1. +1 −2 sklearn/metrics/cluster/supervised.py
@@ -776,8 +776,7 @@ def expected_mutual_information(contingency, n_samples):
def entropy(labels):
"""Calculates the entropy for a labeling."""
- pi = np.array([np.sum(labels == i) for i in np.unique(labels)],
- dtype='float')
+ pi = np.bincount(labels).astype(np.float)
pi = pi[pi > 0]
pi /= np.sum(pi)
return -np.sum(pi * np.log(pi))

0 comments on commit a97e6c8

Please sign in to comment.