Permalink
Browse files

ENH fix if entropy is zero in normalized_mutual_info_score

  • Loading branch information...
1 parent 94fee95 commit 5cbd197581d221273b87bfdc346dcf7e95d438ec @amueller amueller committed Apr 27, 2012
Showing with 3 additions and 3 deletions.
  1. +3 −3 sklearn/metrics/cluster/supervised.py
@@ -673,8 +673,8 @@ def normalized_mutual_info_score(labels_true, labels_pred):
See also
--------
adjusted_rand_score: Adjusted Rand Index
- adjusted_mutual_information_score: Adjusted Mutual Information (recent
- modification of NMI)
+ adjusted_mutual_information_score: Adjusted Mutual Information (adjusted
+ against chance)
Examples
--------
@@ -711,7 +711,7 @@ def normalized_mutual_info_score(labels_true, labels_pred):
# Calculate the expected value for the mutual information
# Calculate entropy for each labeling
h_true, h_pred = entropy(labels_true), entropy(labels_pred)
- nmi = mi / np.sqrt(h_true * h_pred)
+ nmi = mi / max(np.sqrt(h_true * h_pred), 1e-10)
return nmi

0 comments on commit 5cbd197

Please sign in to comment.