Class: Binarizer

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

Read more in the User Guide.

Python Reference

Constructors

new Binarizer()

new Binarizer(opts?): Binarizer

Parameters

ParameterTypeDescription
opts?object-
opts.copy?booleanSet to false to perform inplace binarization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix).
opts.threshold?numberFeature 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.

Returns Binarizer

Defined in generated/preprocessing/Binarizer.ts:29

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/preprocessing/Binarizer.ts:27
_isInitializedbooleanfalsegenerated/preprocessing/Binarizer.ts:26
_pyPythonBridgeundefinedgenerated/preprocessing/Binarizer.ts:25
idstringundefinedgenerated/preprocessing/Binarizer.ts:22
optsanyundefinedgenerated/preprocessing/Binarizer.ts:23

Accessors

feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/preprocessing/Binarizer.ts:403


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/preprocessing/Binarizer.ts:378


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/preprocessing/Binarizer.ts:48

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/preprocessing/Binarizer.ts:99


fit()

fit(opts): Promise<any>

Only validates estimator’s parameters.

This method allows to: (i) validate the estimator’s parameters and (ii) be consistent with the scikit-learn transformer API.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeThe data.
opts.y?anyIgnored.

Returns Promise<any>

Defined in generated/preprocessing/Binarizer.ts:118


fit_transform()

fit_transform(opts): Promise<any[]>

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

ParameterTypeDescription
optsobject-
opts.fit_params?anyAdditional fit parameters.
opts.X?ArrayLike[]Input samples.
opts.y?ArrayLikeTarget values (undefined for unsupervised transformations).

Returns Promise<any[]>

Defined in generated/preprocessing/Binarizer.ts:157


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

Get output feature names for transformation.

Parameters

ParameterTypeDescription
optsobject-
opts.input_features?anyInput features.

Returns Promise<any>

Defined in generated/preprocessing/Binarizer.ts:199


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/preprocessing/Binarizer.ts:235


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/preprocessing/Binarizer.ts:61


set_output()

set_output(opts): Promise<any>

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters

ParameterTypeDescription
optsobject-
opts.transform?"default" | "pandas" | "polars"Configure output of transform and fit_transform.

Returns Promise<any>

Defined in generated/preprocessing/Binarizer.ts:271


set_transform_request()

set_transform_request(opts): Promise<any>

Request metadata passed to the transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.copy?string | booleanMetadata routing for copy parameter in transform.

Returns Promise<any>

Defined in generated/preprocessing/Binarizer.ts:307


transform()

transform(opts): Promise<ArrayLike>

Binarize each element of X.

Parameters

ParameterTypeDescription
optsobject-
opts.copy?booleanCopy the input X or not.
opts.X?ArrayLikeThe data to binarize, element by element. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy.

Returns Promise<ArrayLike>

Defined in generated/preprocessing/Binarizer.ts:341