Skip to main content

MinMaxScaler

Linearly scales each feature to a specified range [min,max][\text{min},\, \text{max}] (default [0,1][0, 1]), based on the per-feature minimum and maximum observed during fitting.

Formula

Zij=XijXjminXjmaxXjmin(maxmin)+minZ_{ij} = \frac{X_{ij} - X_j^{\min}}{X_j^{\max} - X_j^{\min}} \cdot (\text{max} - \text{min}) + \text{min}

If Xjmax=XjminX_j^{\max} = X_j^{\min} for a feature (zero range), the feature is set to min\text{min}.

When to Use

  • Bounded outputs: When the algorithm requires inputs in a fixed range (e.g., neural networks with sigmoid activations).
  • Preserves zeros: Unlike StandardScaler, MinMaxScaler to [0,1][0, 1] maps zero to a non-negative value, but does not center the data.
  • Sensitive to outliers: A single extreme value can compress the rest of the data into a narrow range. For robustness, consider RobustScaler.

Mirrors sklearn.preprocessing.MinMaxScaler.

Constructor

Skigen::MinMaxScaler<Scalar> scaler({min, max}, bool clip = false);
ParameterDefaultDescription
feature_range{0, 1}Target range
clipfalseClip to range after transform

Methods

MethodDescription
fit(X)Compute per-feature min and max
transform(X)Scale to target range
fit_transform(X)Fit and transform in one call
inverse_transform(Z)Recover original scale
transform_inplace(X)Scale in-place
inverse_transform_inplace(Z)Recover in-place

Fitted Attributes

AccessorTypeDescription
data_min()RowVectorTypePer-feature minimum
data_max()RowVectorTypePer-feature maximum
scale()RowVectorTypePer-feature scale factor

Example

#include <Skigen/Preprocessing>

Skigen::MinMaxScaler scaler({0, 1});
scaler.fit(X);
auto X_scaled = scaler.transform(X);
// All values now in [0, 1]