Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Class

Normalizer

Normalizer rescales each nonzero sample independently to unit l1, l2, or max norm. It supports dense and sparse data and is stateless, so it does not need fitting.

How it works

Normalizer rescales each nonzero row independently so its selected norm is one. It is stateless because normalization depends on each sample rather than on statistics learned from the dataset, so fitting is unnecessary for determining the transformation.

Syntax

class sklearn.preprocessing.Normalizer(*, norm='l2', copy=True)

Parameters

NameTypeDescription
norm{'l1', 'l2', 'max'}, default='l2'Norm used for each nonzero sample: 'l1', 'l2', or 'max'; default is 'l2'.
copybool, default=TrueWhether to copy the input; set False to request in-place normalization for compatible NumPy arrays or CSR matrices.

Returns

transform(X, copy=None): scaled X in which each nonzero row has unit norm.

Key points

  • Normalizer operates on individual samples rather than normalizing each feature across the dataset.
  • Every nonzero row is rescaled independently of the other rows.
  • The selected norm for each nonzero row becomes one; supported settings are l1, l2, and max.
  • Dense NumPy arrays and SciPy sparse matrices are accepted.
  • No learned state is required, so fitting does not calculate normalization statistics.
  • The norm parameter selects how each nonzero sample is scaled.

Common mistakes

  • For sparse input, prefer CSR format to avoid an additional copy or conversion.
  • Setting copy=False can mutate compatible dense arrays or CSR matrices in place; use it only when that side effect is acceptable.

Example: Normalize rows independently

from sklearn.preprocessing import Normalizer

X = [[3.0, 4.0], [0.0, 0.0]]
X_normalized = Normalizer(norm="l2").fit_transform(X)
print(X_normalized)

Normalizes each nonzero row independently; the zero row remains zero.

When to use it

Text classification

Text feature vectors should be compared by direction rather than total magnitude.

Sparse preprocessing

Sparse feature matrices need row-wise unit scaling before a downstream estimator.

Pipeline preprocessing

A pipeline requires a transformer that normalizes each incoming sample independently.

Interview questions

QHow does Normalizer differ from a feature-wise scaler?

Normalizer transforms samples row by row, independently of other samples, so each nonzero row receives the requested unit norm. Unlike a feature scaler, it does not estimate dataset-wide parameters.

Follow-up: What does fitting learn? Nothing: the estimator is stateless, so fit is effectively unnecessary and transform can perform the operation directly.

QWhich normalization modes are supported?

The default is the l2 norm. The norm option also accepts l1 and max; with max, each row is rescaled according to its largest absolute value.

Follow-up: When might max normalization be useful? It bounds each row by its largest absolute component, which can be appropriate when relative magnitudes within a sample matter more than Euclidean length.

QWhat input representations does Normalizer support?

The class accepts dense NumPy arrays and scipy sparse matrices. CSR sparse matrices are preferred when avoiding copy or conversion overhead matters.

Follow-up: What does copy=False change? It requests in-place row normalization for compatible NumPy arrays or CSR matrices, so callers must account for input mutation.

  • normalize
  • Normalizer

Source: Normalizer. Checked 2026-10-15.