Documentation
Classes
Normalizer

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 (opens in a new tab)

Constructors

constructor()

Signature

new Normalizer(opts?: object): Normalizer;

Parameters

NameTypeDescription
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). Default Value true
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. Default Value 'l2'

Returns

Normalizer

Defined in: generated/preprocessing/Normalizer.ts:31 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

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

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/preprocessing/Normalizer.ts:103 (opens in a new tab)

fit()

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.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
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:122 (opens in a new tab)

fit_transform()

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit\_params and returns a transformed version of X.

Signature

fit_transform(opts: object): Promise<any[]>;

Parameters

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

Returns

Promise<any[]>

Defined in: generated/preprocessing/Normalizer.ts:162 (opens in a new tab)

get_feature_names_out()

Get output feature names for transformation.

Signature

get_feature_names_out(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.input_features?anyInput features.

Returns

Promise<any>

Defined in: generated/preprocessing/Normalizer.ts:209 (opens in a new tab)

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Signature

get_metadata_routing(opts: object): Promise<any>;

Parameters

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

Returns

Promise<any>

Defined in: generated/preprocessing/Normalizer.ts:247 (opens in a new tab)

init()

Initializes the underlying Python resources.

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

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/preprocessing/Normalizer.ts:63 (opens in a new tab)

set_output()

Set output container.

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

Signature

set_output(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.transform?"default" | "pandas"Configure output of transform and fit\_transform.

Returns

Promise<any>

Defined in: generated/preprocessing/Normalizer.ts:284 (opens in a new tab)

set_transform_request()

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:

Signature

set_transform_request(opts: object): Promise<any>;

Parameters

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

Returns

Promise<any>

Defined in: generated/preprocessing/Normalizer.ts:321 (opens in a new tab)

transform()

Scale each non zero row of X to unit norm.

Signature

transform(opts: object): Promise<ArrayLike>;

Parameters

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

Returns

Promise<ArrayLike>

Defined in: generated/preprocessing/Normalizer.ts:356 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/preprocessing/Normalizer.ts:29 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/preprocessing/Normalizer.ts:28 (opens in a new tab)

_py

PythonBridge

Defined in: generated/preprocessing/Normalizer.ts:27 (opens in a new tab)

id

string

Defined in: generated/preprocessing/Normalizer.ts:24 (opens in a new tab)

opts

any

Defined in: generated/preprocessing/Normalizer.ts:25 (opens in a new tab)

Accessors

feature_names_in_

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

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/preprocessing/Normalizer.ts:421 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/preprocessing/Normalizer.ts:396 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/preprocessing/Normalizer.ts:50 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/preprocessing/Normalizer.ts:54 (opens in a new tab)