# LabelBinarizer

### *class* cuml.preprocessing.LabelBinarizer(, neg_label=0, pos_label=1, sparse_output=False, verbose=False, output_type=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/preprocessing/label.py#L256)

Binarize labels in a one-vs-all fashion.

* **Parameters:**
  **neg_label**
  : The value to use for encoding negative labels.

  **pos_label**
  : The value to use for encoding positive labels.

  **sparse_output**
  : If true, a sparse CSR matrix is returned from `transform`.

  **verbose**
  : Sets logging level. It must be one of `cuml.common.logger.level_*`.
    See [Verbosity Levels](../../cuml/index.html.md#verbosity-levels) for more info.

  **output_type**
  : 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](../../cuml/index.html.md#output-data-type-configuration) for more info.
* **Attributes:**
  **classes_**
  : Holds the label for each class.

  **y_type_**
  : The type of the target data.

  **sparse_input_**
  : Whether the input data to [`fit`](#cuml.preprocessing.LabelBinarizer.fit) was a sparse matrix.

### Methods

| [`fit`](#cuml.preprocessing.LabelBinarizer.fit)(y)                                | Fit label binarizer.                                       |
|----------------------------------------------------------------------------------------|------------------------------------------------------------|
| [`fit_transform`](#cuml.preprocessing.LabelBinarizer.fit_transform)(y)                      | Fit label binarizer and transform labels to binary labels. |
| [`inverse_transform`](#cuml.preprocessing.LabelBinarizer.inverse_transform)(y, \*[, threshold]) | Transform binary labels back to original labels.           |
| [`transform`](#cuml.preprocessing.LabelBinarizer.transform)(y)                          | Transform labels to binary labels.                         |

#### SEE ALSO
[`label_binarize`](../cuml.preprocessing.label_binarize/index.html.md#cuml.preprocessing.label_binarize)
: A function version of this class.

### Examples

```pycon
>>> import cupy as cp
>>> from cuml.preprocessing import LabelBinarizer
>>> y = cp.array([1, 2, 6, 4, 2])
>>> lb = LabelBinarizer().fit(y)
>>> lb.classes_
array([1, 2, 4, 6])
>>> lb.transform(cp.array([1, 6]))
array([[1, 0, 0, 0],
       [0, 0, 0, 1]], dtype=int32)
```

Binary targets result in a column vector:

```pycon
>>> import numpy as np
>>> lb = LabelBinarizer()
>>> lb.fit_transform(np.array(['a', 'b', 'b', 'a']))
array([[0],
       [1],
       [1],
       [0]], dtype=int32)
```

<!-- !! processed by numpydoc !! -->

#### as_sklearn()[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/interop.py#L206)

Convert this estimator into an equivalent scikit-learn (or scikit-learn
extension) estimator.

* **Returns:**
  sklearn.base.BaseEstimator
  : A scikit-learn compatible estimator instance that mirrors the trained
    state of the current estimator.

<!-- !! processed by numpydoc !! -->

#### fit(y) → [LabelBinarizer](#cuml.preprocessing.LabelBinarizer)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/preprocessing/label.py#L377)

Fit label binarizer.

* **Parameters:**
  **y**
  : Target values. The 2-d matrix should only contain 0 and 1,
    in the multilabel-indicator format.
* **Returns:**
  **self**
  : Returns the instance itself.

<!-- !! processed by numpydoc !! -->

#### fit_transform(y)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/preprocessing/label.py#L396)

Fit label binarizer and transform labels to binary labels.

* **Parameters:**
  **y**
  : Target values. The 2-d matrix should only contain 0 and 1, in the
    multilabel-indicator format.
* **Returns:**
  **y**
  : The encoded labels. Shape will be (n_samples, 1) for binary
    classification problems. Will be a sparse matrix if
    `sparse_output=True`.

<!-- !! processed by numpydoc !! -->

#### *classmethod* from_sklearn(model)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/interop.py#L222)

Create a cuml estimator from a scikit-learn estimator.

* **Parameters:**
  **model**
  : A compatible scikit-learn (or scikit-learn extension) estimator.
* **Returns:**
  cls
  : A new instance of this cuml estimator class that mirrors the
    state of the input estimator.

### Notes

`output_type` of the estimator is set to “numpy” by default, as these
cannot be inferred from training arguments. If something different is
required, then please use cuml’s output_type configuration utilities.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn’t
have to override this method

<!-- !! processed by numpydoc !! -->

#### inverse_transform(y, , threshold=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/preprocessing/label.py#L456)

Transform binary labels back to original labels.

* **Parameters:**
  **y**
  : The encoded target values.

  **threshold**
  : Threshold used in the binary and multilabel-indicator cases.
    If None, the threshold is assumed to be half way between
    `neg_label` and `pos_label`.
* **Returns:**
  **y**
  : The original target values.

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn’t have to override this method

<!-- !! processed by numpydoc !! -->

#### transform(y)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/preprocessing/label.py#L425)

Transform labels to binary labels.

* **Parameters:**
  **y**
  : Target values. The 2-d matrix should only contain 0 and 1, in the
    multilabel-indicator format.
* **Returns:**
  **y**
  : 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).

<!-- !! processed by numpydoc !! -->
