Skip to content

Commit

Permalink
Merge 2fabc0d into 9790bc6
Browse files Browse the repository at this point in the history
  • Loading branch information
ysk24ok committed Dec 17, 2015
2 parents 9790bc6 + 2fabc0d commit 19d662d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sklearn/preprocessing/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from collections import defaultdict
import itertools
import array
import warnings

import numpy as np
import scipy.sparse as sp
Expand Down Expand Up @@ -295,6 +296,9 @@ def fit(self, y):

self.sparse_input_ = sp.issparse(y)
self.classes_ = unique_labels(y)
if len(self.classes_) == 1:
warnings.warn("Only one label in y and this label will be "
"regarded as negative one.")
return self

def transform(self, y):
Expand Down
3 changes: 3 additions & 0 deletions sklearn/preprocessing/tests/test_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sklearn.utils.testing import assert_array_equal
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_raises
from sklearn.utils.testing import assert_warns_message
from sklearn.utils.testing import ignore_warnings

from sklearn.preprocessing.label import LabelBinarizer
Expand Down Expand Up @@ -43,6 +44,8 @@ def test_label_binarizer():
assert_array_equal(lb.classes_, ["pos"])
assert_array_equal(expected, got)
assert_array_equal(lb.inverse_transform(got), inp)
w = "Only one label in y and this label will be regarded as negative one."
assert_warns_message(UserWarning, w, lb.fit, inp)

# two-class case
inp = ["neg", "pos", "pos", "neg"]
Expand Down

0 comments on commit 19d662d

Please sign in to comment.