# LabelEncoder

### *class* cuml.preprocessing.LabelEncoder(, handle_unknown='error', verbose=False, output_type=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/preprocessing/_label.py#L15)

Encode target labels with values between 0 and n_classes - 1.

This transformer should be used to encode target values (`y`) and not the
input `X`.

* **Parameters:**
  **handle_unknown**
  : Whether to raise an error or ignore if an unknown categorical feature
    is present during transform (default is to raise). When this parameter
    is set to ‘ignore’ and an unknown category is encountered during
    transform or inverse transform, the resulting encoding will be null.

  **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.

### Methods

| [`fit`](#cuml.preprocessing.LabelEncoder.fit)(y)               | Fit a LabelEncoder instance to a set of categories.   |
|-----------------------------------------------------------------------|-------------------------------------------------------|
| [`fit_transform`](#cuml.preprocessing.LabelEncoder.fit_transform)(y)     | Simultaneously fit and transform an input.            |
| [`inverse_transform`](#cuml.preprocessing.LabelEncoder.inverse_transform)(y) | Transform labels back to original encoding.           |
| [`transform`](#cuml.preprocessing.LabelEncoder.transform)(y)         | Transform an input into its categorical keys.         |

### Examples

```pycon
>>> import numpy as np
>>> from cuml.preprocessing import LabelEncoder
>>> y = np.array(["apple", "apple", "banana", "grape"])
>>> le = LabelEncoder()
>>> le.fit_transform(y)
array([0, 0, 1, 2], dtype=int8)
>>> le.classes_
array(['apple', 'banana', 'grape'], dtype='<U6')
```

<!-- !! 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)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/preprocessing/_label.py#L133)

Fit a LabelEncoder instance to a set of categories.

* **Parameters:**
  **y**
  : Dense matrix with any dtype.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
* **Returns:**
  **self**
  : Fitted label encoder.

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

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

Simultaneously fit and transform an input.

This is functionally equivalent to (but faster than)
`LabelEncoder().fit(y).transform(y)`.

* **Parameters:**
  **y**
  : Dense matrix with any dtype.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
* **Returns:**
  **y**
  : Encoded labels.
    <br/>
    For more information on how to configure cuML’s output type,
    refer to: [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration).

<!-- !! 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)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/preprocessing/_label.py#L188)

Transform labels back to original encoding.

* **Parameters:**
  **y**
  : Dense matrix with any dtype.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
* **Returns:**
  **y_original**
  : Original encoding.
    <br/>
    For more information on how to configure cuML’s output type,
    refer to: [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration).

<!-- !! 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#L148)

Transform an input into its categorical keys.

This is intended for use with small inputs relative to the size of the
dataset. For fitting and transforming an entire dataset, prefer
[`fit_transform`](#cuml.preprocessing.LabelEncoder.fit_transform).

* **Parameters:**
  **y**
  : Dense matrix with any dtype.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
* **Returns:**
  **y**
  : Encoded labels.
    <br/>
    For more information on how to configure cuML’s output type,
    refer to: [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration).

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