Binarizer#

class cuml.preprocessing.Binarizer(*args, **kwargs)[source]#

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:
thresholdfloat, optional (0.0 by default)

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.

copyboolean, optional, default True

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

Methods

fit(X[, y])

Do nothing and return the estimator unchanged

transform(X[, copy])

Binarize each element of X

See also

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

>>> 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.]])
fit(X, y=None) Binarizer[source]#

Do nothing and return the estimator unchanged

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

Parameters:
X{array-like, sparse matrix}
transform(X, copy=None) SparseCumlArray[source]#

Binarize each element of X

Parameters:
X{array-like, sparse matrix}, shape [n_samples, n_features]

The data to binarize, element by element.

copybool

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