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.
Constructors
new Binarizer()
new Binarizer(
opts
?):Binarizer
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.copy ? | boolean | Set 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 ? | number | 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. |
Returns Binarizer
Defined in generated/preprocessing/Binarizer.ts:29
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/preprocessing/Binarizer.ts:27 |
_isInitialized | boolean | false | generated/preprocessing/Binarizer.ts:26 |
_py | PythonBridge | undefined | generated/preprocessing/Binarizer.ts:25 |
id | string | undefined | generated/preprocessing/Binarizer.ts:22 |
opts | any | undefined | generated/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
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The data. |
opts.y ? | any | Ignored. |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Additional fit parameters. |
opts.X ? | ArrayLike [] | Input samples. |
opts.y ? | ArrayLike | Target 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.input_features ? | any | Input 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A 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
Parameter | Type |
---|---|
py | PythonBridge |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.copy ? | string | boolean | Metadata 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.copy ? | boolean | Copy the input X or not. |
opts.X ? | ArrayLike | The 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