# Binarizer

### *class* cuml.preprocessing.Binarizer(\*args, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L2020)

Binarize data (set feature values to 0 or 1) according to a threshold

Values greater than the threshold map to 1, while values less than
or equal to the threshold map to 0. With the default threshold of 0,
only positive values map to 1.

Binarization is a common operation on text count data where the
analyst can decide to only consider the presence or absence of a
feature rather than a quantified number of occurrences for instance.

It can also be used as a pre-processing step for estimators that
consider boolean random variables (e.g. modelled using the Bernoulli
distribution in a Bayesian setting).

* **Parameters:**
  **threshold**
  : Feature values below or equal to this are replaced by 0, above it by 1.
    Threshold may not be less than 0 for operations on sparse matrices.

  **copy**
  : Whether a forced copy will be triggered. If copy=False, a copy might
    be triggered by a conversion.

### Methods

| [`fit`](#cuml.preprocessing.Binarizer.fit)(X[, y])          | Do nothing and return the estimator unchanged   |
|-----------------------------------------------------------------------|-------------------------------------------------|
| [`transform`](#cuml.preprocessing.Binarizer.transform)(X[, copy]) | Binarize each element of X                      |

#### SEE ALSO
[`binarize`](../cuml.preprocessing.binarize/index.html.md#cuml.preprocessing.binarize)
: Equivalent function without the estimator API.

### Notes

If the input is a sparse matrix, only the non-zero values are subject
to update by the Binarizer class.

This estimator is stateless (besides constructor parameters), the
fit method does nothing but is useful when used in a pipeline.

### Examples

```pycon
>>> from cuml.preprocessing import Binarizer
>>> import cupy as cp
>>> X = [[ 1., -1.,  2.],
...      [ 2.,  0.,  0.],
...      [ 0.,  1., -1.]]
>>> X = cp.array(X)
>>> transformer = Binarizer().fit(X)  # fit does nothing.
>>> transformer
Binarizer()
>>> transformer.transform(X)
array([[1., 0., 1.],
       [1., 0., 0.],
       [0., 1., 0.]])
```

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

#### fit(X, y=None) → [Binarizer](#cuml.preprocessing.Binarizer)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L2088)

Do nothing and return the estimator unchanged

This method is just there to implement the usual API and hence
work in pipelines.

* **Parameters:**
  **X**

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

#### fit_transform(X, y=None, \*\*fit_params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/utils/skl_dependencies.py#L42)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params
and returns a transformed version of X.

* **Parameters:**
  **X**

  **y**
  : Target values.

  **\*\*fit_params**
  : Additional fit parameters.
* **Returns:**
  **X_new**
  : Transformed array.

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

#### get_feature_names_out(input_features=None)

Get output feature names for transformation.

* **Parameters:**
  **input_features**
  : Input features.
    - If `input_features` is [`None`](https://docs.python.org/3/builtins/constants.html#None), then `feature_names_in_` is
      used as feature names in. If `feature_names_in_` is not defined,
      then the following input feature names are generated:
      `["x0", "x1", ..., "x(n_features_in_ - 1)"]`.
    - If `input_features` is an array-like, then `input_features` must
      match `feature_names_in_` if `feature_names_in_` is defined.
* **Returns:**
  **feature_names_out**
  : Same as input features.

<!-- !! 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 !! -->

#### 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(X, copy=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L2102)

Binarize each element of X

* **Parameters:**
  **X**
  : The data to binarize, element by element.

  **copy**
  : Whether a forced copy will be triggered. If copy=False,
    a copy might be triggered by a conversion.

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