LabelBinarizer#

class cuml.preprocessing.LabelBinarizer(*, neg_label=0, pos_label=1, sparse_output=False, verbose=False, output_type=None)[source]#

A multi-class dummy encoder for labels.

Parameters:
neg_labelinteger (default=0)

label to be used as the negative binary label

pos_labelinteger (default=1)

label to be used as the positive binary label

sparse_outputbool (default=False)

whether to return sparse arrays for transformed output

verboseint or boolean, default=False

Sets logging level. It must be one of cuml.common.logger.level_*. See Verbosity Levels for more info.

output_type{‘input’, ‘array’, ‘dataframe’, ‘series’, ‘df_obj’, ‘numba’, ‘cupy’, ‘numpy’, ‘cudf’, ‘pandas’}, default=None

Return results and set estimator attributes to the indicated output type. If None, the output type set at the module level (cuml.global_settings.output_type) will be used. See Output Data Type Configuration for more info.

Attributes:
classes_

Methods

fit(y)

Fit label binarizer

fit_transform(y)

Fit label binarizer and transform multi-class labels to their dummy-encoded representation.

inverse_transform(y, *[, threshold])

Transform binary labels back to original multi-class labels

transform(y)

Transform multi-class labels to their dummy-encoded representation labels.

Examples

Create an array with labels and dummy encode them

>>> import cupy as cp
>>> import cupyx
>>> from cuml.preprocessing import LabelBinarizer

>>> labels = cp.asarray([0, 5, 10, 7, 2, 4, 1, 0, 0, 4, 3, 2, 1],
...                     dtype=cp.int32)

>>> lb = LabelBinarizer()
>>> encoded = lb.fit_transform(labels)
>>> print(str(encoded))
[[1 0 0 0 0 0 0 0]
[0 0 0 0 0 1 0 0]
[0 0 0 0 0 0 0 1]
[0 0 0 0 0 0 1 0]
[0 0 1 0 0 0 0 0]
[0 0 0 0 1 0 0 0]
[0 1 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0]
[0 0 0 0 1 0 0 0]
[0 0 0 1 0 0 0 0]
[0 0 1 0 0 0 0 0]
[0 1 0 0 0 0 0 0]]
>>> decoded = lb.inverse_transform(encoded)
>>> print(str(decoded))
[ 0  5 10  7  2  4  1  0  0  4  3  2  1]
fit(y) LabelBinarizer[source]#

Fit label binarizer

Parameters:
yarray of shape [n_samples,] or [n_samples, n_classes]

Target values. The 2-d matrix should only contain 0 and 1, represents multilabel classification.

Returns:
selfreturns an instance of self.
fit_transform(y) SparseCumlArray[source]#

Fit label binarizer and transform multi-class labels to their dummy-encoded representation.

Parameters:
yarray of shape [n_samples,] or [n_samples, n_classes]
Returns:
arrarray with encoded labels
inverse_transform(y, *, threshold=None) CumlArray[source]#

Transform binary labels back to original multi-class labels

Parameters:
yarray of shape [n_samples, n_classes]
thresholdfloat this value is currently ignored
Returns:
arrarray with original labels
transform(y) SparseCumlArray[source]#

Transform multi-class labels to their dummy-encoded representation labels.

Parameters:
yarray of shape [n_samples,] or [n_samples, n_classes]
Returns:
arrarray with encoded labels