Skip to content

Commit

Permalink
Fix minor errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rsivapr committed Sep 14, 2013
1 parent 62fc931 commit 715ef0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion sklearn/preprocessing/label.py
Expand Up @@ -6,6 +6,8 @@

import numpy as np

from scipy.sparse import csc_matrix

from ..base import BaseEstimator, TransformerMixin

from ..utils.fixes import unique
Expand Down Expand Up @@ -396,7 +398,7 @@ def label_binarize(y, classes, multilabel=False, neg_label=0, pos_label=1):
return y
if neg_label != 0:
# neg_label not zero eliminates possibility of a sparse matrix
Y = np.zeros((len(y), len(classes)
Y = np.zeros((len(y), len(classes)), dtype=np.int)
Y += neg_label
else:
Y = np.zeros((len(y), 1), dtype=np.int)
Expand All @@ -413,6 +415,7 @@ def label_binarize(y, classes, multilabel=False, neg_label=0, pos_label=1):
imap = dict((v, k) for k, v in enumerate(classes))

if neg_label == 0:
row, col, data = ([] for i in range(3))
for i, label_tuple in enumerate(y):
for label in label_tuple:
row.append(i)
Expand Down
6 changes: 3 additions & 3 deletions sklearn/utils/multiclass.py
Expand Up @@ -146,10 +146,10 @@ def is_label_indicator_matrix(y):
if not (hasattr(y, "shape") and y.ndim == 2 and y.shape[1] > 1):
return False
try:
n_labels = len(np.unique(y))
labels = np.unique(y)
except TypeError:
n_labels = len(np.unique(y.data)) + 1
return n_labels <= 2 and (y.dtype.kind in 'biu' # bool, int, uint
labels = np.setxor1d(y.data, [0])
return len(labels) <= 2 and (y.dtype.kind in 'biu' # bool, int, uint
or _is_integral_float(labels))


Expand Down

0 comments on commit 715ef0c

Please sign in to comment.