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.

Python Reference

Constructors

new Normalizer()

new Normalizer(opts?): Normalizer

Parameters

ParameterTypeDescription
opts?object-
opts.copy?booleanSet 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

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/preprocessing/Normalizer.ts:29
_isInitializedbooleanfalsegenerated/preprocessing/Normalizer.ts:28
_pyPythonBridgeundefinedgenerated/preprocessing/Normalizer.ts:27
idstringundefinedgenerated/preprocessing/Normalizer.ts:24
optsanyundefinedgenerated/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

ParameterType
pythonBridgePythonBridge

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

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeThe data to estimate the normalization parameters.
opts.y?anyNot 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

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/Normalizer.ts:160


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/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

ParameterTypeDescription
optsobject-
opts.routing?anyA 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

ParameterType
pyPythonBridge

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

ParameterTypeDescription
optsobject-
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

ParameterTypeDescription
optsobject-
opts.copy?string | booleanMetadata 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

ParameterTypeDescription
optsobject-
opts.copy?booleanCopy the input X or not.
opts.X?ArrayLikeThe 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