Skip to main content

MaxAbsScaler

Scales each feature by its maximum absolute value, mapping all features to the range [−1,1][-1, 1]. Unlike StandardScaler and MinMaxScaler, MaxAbsScaler does not shift the data (no centering), so it preserves sparsity.

Formula​

Zij=Xijmax⁡i∣Xij∣Z_{ij} = \frac{X_{ij}}{\max_i |X_{ij}|}

If max⁡i∣Xij∣=0\max_i |X_{ij}| = 0 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​

MethodDescription
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​

AccessorTypeDescription
max_abs()RowVectorTypePer-feature max absolute value
scale()RowVectorTypePer-feature scale factor

Example​

#include <Skigen/Preprocessing>

Skigen::MaxAbsScaler scaler;
auto X_scaled = scaler.fit_transform(X);