Toggle Menu
Prev Up Next

scikit-learn 1.3.2
Other versions

Please cite us if you use the software.

# `sklearn.preprocessing`.binarize

sklearn.preprocessing.binarize(X, *, threshold=0.0, copy=True)

  Boolean thresholding of array-like or scipy.sparse matrix.

  Read more in the User Guide.

  Parameters:
    X{array-like, sparse matrix} of shape (n_samples, n_features)

      The data to binarize, element by element. scipy.sparse matrices should be in CSR or CSC format to avoid an un-necessary copy.

    threshold float, default=0.0

      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 bool, default=True

      Set to False to perform inplace binarization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR / CSC matrix and if axis is 1).

  Returns:
    X_tr{ndarray, sparse matrix} of shape (n_samples, n_features)

      The transformed data.

  See also

  `Binarizer`

    Performs binarization using the Transformer API (e.g. as part of a preprocessing `Pipeline`).