Normalizer
Normalizes each row (sample) independently to unit norm. This is a stateless transformer — fit is a no-op.
Formula
where is the -th row (sample) of .
Note that Normalizer operates row-wise (per sample), unlike StandardScaler and other scalers which operate column-wise (per feature). This is a fundamental distinction.
When to Use
- Text classification: After TF-IDF vectorization, L2 normalization ensures that documents of different lengths are comparable.
- Cosine similarity: L2-normalized vectors have , so their dot product equals cosine similarity.
- Kernel methods: Some kernels assume unit-norm inputs.
Mirrors sklearn.preprocessing.Normalizer.
Constructor
Skigen::Normalizer<Scalar> normalizer(Norm norm = Norm::L2);
| Parameter | Default | Description |
|---|---|---|
norm | L2 | Norm to use: L1, L2, or Max |
Methods
| Method | Description |
|---|---|
fit(X) | No-op (stateless) |
transform(X) | Normalize each row |
transform_inplace(X) | Normalize in-place |
Example
#include <Skigen/Preprocessing>
Skigen::Normalizer normalizer(Skigen::Normalizer<>::Norm::L2);
auto X_normed = normalizer.fit_transform(X);
// Each row now has unit L2 norm