Skip to content

Commit eec979c

Browse files
jnothmanHamzeh Alsalhi
authored andcommitted
DOC give example of binarizing binary targets
H/T @ilam
1 parent bd7db7b commit eec979c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sklearn/preprocessing/label.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ class LabelBinarizer(BaseEstimator, TransformerMixin):
211211
array([[1, 0, 0, 0],
212212
[0, 0, 0, 1]])
213213
214+
Binary targets transform to a column vector
215+
>>> lb = preprocessing.LabelBinarizer()
216+
>>> lb.fit_transform(['yes', 'no', 'no', 'yes'])
217+
array([[1],
218+
[0],
219+
[0],
220+
[1]])
221+
214222
>>> import numpy as np
215223
>>> lb.fit(np.array([[0, 1, 1], [1, 0, 0]]))
216224
LabelBinarizer(neg_label=0, pos_label=1)
@@ -399,6 +407,14 @@ def label_binarize(y, classes, multilabel=False, neg_label=0, pos_label=1):
399407
array([[1, 0, 0, 0],
400408
[0, 1, 0, 0]])
401409
410+
Binary targets transform to a column vector
411+
412+
>>> label_binarize(['yes', 'no', 'no', 'yes'], classes=['no', 'yes'])
413+
array([[1],
414+
[0],
415+
[0],
416+
[1]])
417+
402418
See also
403419
--------
404420
label_binarize : function to perform the transform operation of

0 commit comments

Comments
 (0)