label_binarize#

cuml.preprocessing.label_binarize(y, classes, neg_label=0, pos_label=1, sparse_output=False)[source]#

Binarize labels in a one-vs-all fashion.

Parameters:
yarray-like or sparse matrix, shape (n_samples,) or (n_samples, n_classes)

Target values. The 2-d matrix should only contain 0 and 1, in the multilabel-indicator format.

classesarray-like of shape (n_classes,)

The class labels for each class.

neg_labelint, default=0

The value to use for encoding negative labels.

pos_labelint, default=1

The value to use for encoding positive labels.

sparse_outputbool, default=False

If true, a sparse CSR matrix is returned.

Returns:
yarray or sparse matrix, shape (n_samples, n_classes)

The encoded labels. Will be a sparse matrix if sparse_output=True. Shape will be (n_samples, n_classes) for multiclass problems, (n_samples, 1) for binary problems with no unseen classes, and (n_samples, 2) for binary problems with unseen classes (a minor, intentional deviation from sklearn).

See also

LabelBinarizer

A class version of this function.

Examples

>>> from cuml.preprocessing import label_binarize
>>> label_binarize([1, 6], classes=[1, 2, 4, 6])
array([[1, 0, 0, 0],
       [0, 0, 0, 1]], dtype=int32)

Binary targets result in a column vector:

>>> label_binarize(['a', 'b', 'b', 'a'], classes=['a', 'b'])
array([[0],
       [1],
       [1],
       [0]], dtype=int32)