Class: Normalizer
Normalize samples individually to unit norm.
Each sample (i.e. each row of the data matrix) with at least one non zero component is rescaled independently of other samples so that its norm (l1, l2 or inf) equals one.
This transformer is able to work both with dense numpy arrays and scipy.sparse matrix (use CSR format if you want to avoid the burden of a copy / conversion).
Scaling inputs to unit norms is a common operation for text classification or clustering for instance. For instance the dot product of two l2-normalized TF-IDF vectors is the cosine similarity of the vectors and is the base similarity metric for the Vector Space Model commonly used by the Information Retrieval community.
For an example visualization, refer to Compare Normalizer with other scalers.
Read more in the User Guide.
Constructors
new Normalizer()
new Normalizer(
opts
?):Normalizer
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.copy ? | boolean | Set to false to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix). |
opts.norm ? | "l1" | "l2" | "max" | The norm to use to normalize each non zero sample. If norm=’max’ is used, values will be rescaled by the maximum of the absolute values. |
Returns Normalizer
Defined in generated/preprocessing/Normalizer.ts:31
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/preprocessing/Normalizer.ts:29 |
_isInitialized | boolean | false | generated/preprocessing/Normalizer.ts:28 |
_py | PythonBridge | undefined | generated/preprocessing/Normalizer.ts:27 |
id | string | undefined | generated/preprocessing/Normalizer.ts:24 |
opts | any | undefined | generated/preprocessing/Normalizer.ts:25 |
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/Normalizer.ts:406
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/preprocessing/Normalizer.ts:381
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/Normalizer.ts:50
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/Normalizer.ts:102
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 to estimate the normalization parameters. |
opts.y ? | any | Not used, present here for API consistency by convention. |
Returns Promise
<any
>
Defined in generated/preprocessing/Normalizer.ts:121
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/Normalizer.ts:160
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/Normalizer.ts:202
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/Normalizer.ts:238
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/Normalizer.ts:63
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/Normalizer.ts:274
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/Normalizer.ts:310
transform()
transform(
opts
):Promise
<ArrayLike
>
Scale each non zero row of X to unit norm.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.copy ? | boolean | Copy the input X or not. |
opts.X ? | ArrayLike | The data to normalize, row by row. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy. |
Returns Promise
<ArrayLike
>
Defined in generated/preprocessing/Normalizer.ts:344