sklearn.preprocessing.label_binarize(y, classes, neg_label=0, pos_label=1, sparse_output=False)
[source]
Binarize labels in a one-vs-all fashion
Several regression and binary classification algorithms are available in scikit-learn. A simple way to extend these algorithms to the multi-class classification case is to use the so-called one-vs-all scheme.
This function makes it possible to compute this transformation for a fixed set of class labels known ahead of time.
Parameters: |
|
---|---|
Returns: |
|
See also
LabelBinarizer
>>> from sklearn.preprocessing import label_binarize >>> label_binarize([1, 6], classes=[1, 2, 4, 6]) array([[1, 0, 0, 0], [0, 0, 0, 1]])
The class ordering is preserved:
>>> label_binarize([1, 6], classes=[1, 6, 4, 2]) array([[1, 0, 0, 0], [0, 1, 0, 0]])
Binary targets transform to a column vector
>>> label_binarize(['yes', 'no', 'no', 'yes'], classes=['no', 'yes']) array([[1], [0], [0], [1]])
sklearn.preprocessing.label_binarize
© 2007–2018 The scikit-learn developers
Licensed under the 3-clause BSD License.
http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.label_binarize.html