Permalink
Browse files

ENH added old confusion_matrix implementation as alternative for few …

…labels.
  • Loading branch information...
1 parent dc01ed3 commit b6e38ce7d18efd78bddd2f282df51795a6129672 @amueller amueller committed Jun 3, 2012
Showing with 10 additions and 3 deletions.
  1. +10 −3 sklearn/metrics/metrics.py
View
@@ -65,9 +65,16 @@ def confusion_matrix(y_true, y_pred, labels=None):
n_labels = labels.size
label_to_ind = dict((y, x) for x, y in enumerate(labels))
- CM = np.zeros((n_labels, n_labels), dtype=np.long)
- for yt, yp in zip(y_true, y_pred):
- CM[label_to_ind[yt], label_to_ind[yp]] += 1
+ if n_labels >= 15:
+ CM = np.zeros((n_labels, n_labels), dtype=np.long)
+ for yt, yp in zip(y_true, y_pred):
+ CM[label_to_ind[yt], label_to_ind[yp]] += 1
+ else:
+ CM = np.empty((n_labels, n_labels), dtype=np.long)
+ for i, label_i in enumerate(labels):
+ for j, label_j in enumerate(labels):
+ CM[i, j] = np.sum(
+ np.logical_and(y_true == label_i, y_pred == label_j))
return CM

0 comments on commit b6e38ce

Please sign in to comment.