MaxAbsScaler
Scales each feature by its maximum absolute value, mapping all features to the range . Unlike StandardScaler and MinMaxScaler, MaxAbsScaler does not shift the data (no centering), so it preserves sparsity.
Formula
If for a feature (all zeros), the feature is left unchanged.
When to Use
- Sparse data: The only scaler (besides Normalizer) that preserves zero entries, making it ideal for sparse matrices.
- Centered data: When the data is already centered and only scaling is needed.
- Preserves sign: The sign of each entry is unchanged, unlike MinMaxScaler which shifts values.
Mirrors sklearn.preprocessing.MaxAbsScaler.
Constructor
Skigen::MaxAbsScaler<Scalar> scaler(bool clip = false);
Methods
| Method | Description |
|---|---|
fit(X) | Compute per-feature max absolute value |
transform(X) | Scale to [-1, 1] |
inverse_transform(Z) | Recover original scale |
transform_inplace(X) | Scale in-place |
Fitted Attributes
| Accessor | Type | Description |
|---|---|---|
max_abs() | RowVectorType | Per-feature max absolute value |
scale() | RowVectorType | Per-feature scale factor |
Example
#include <Skigen/Preprocessing>
Skigen::MaxAbsScaler scaler;
auto X_scaled = scaler.fit_transform(X);