Binarizer#
[1]:
import numpy as np
X = np.array(
[
[1.0, -1.0, 2.0],
[2.0, 0.0, 0.0],
[0.0, 1.0, -1.0],
]
)
X
[1]:
array([[ 1., -1., 2.],
[ 2., 0., 0.],
[ 0., 1., -1.]])
[2]:
from sklearn.preprocessing import Binarizer
binarizer = Binarizer(
# -------------------------------------------------------------------------
# Feature values below or equal to this are replaced by 0, above it by 1.
threshold=0.5,
)
binarizer.fit(X)
binarizer.transform(X)
[2]:
array([[1., 0., 1.],
[1., 0., 0.],
[0., 1., 0.]])