MinMaxScaler
Linearly scales each feature to a specified range (default ), based on the per-feature minimum and maximum observed during fitting.
Formula
If for a feature (zero range), the feature is set to .
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 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);
| Parameter | Default | Description |
|---|---|---|
feature_range | {0, 1} | Target range |
clip | false | Clip to range after transform |
Methods
| Method | Description |
|---|---|
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
| Accessor | Type | Description |
|---|---|---|
data_min() | RowVectorType | Per-feature minimum |
data_max() | RowVectorType | Per-feature maximum |
scale() | RowVectorType | Per-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]