MinMaxScaler transformer.

Min-max normalization to scale features to a specified range.

Classes

MinMaxScaler

class preprocessing.scaling.normalize.MinMaxScaler(Transformer)

Min-max normalization to scale features to a specified range.

Transforms features by scaling each feature to a given range, typically [0, 1].
Constructor
__init__(
    self,
    scale: float = 1.0,
    translation: float = 0.0,
    columns: Optional[List[int]] = None,
)

Overview

Min-max scaling is a common normalization technique that preserves the relative distances between values while mapping them into a bounded interval.

Theory

The transformation is given by:

x_{scaled} = \frac{x - \min(x_{train})}{\max(x_{train}) - \min(x_{train})} \cdot S + T

where S is the scale (default 1.0) and T is the translation (default 0.0).

Parameters

scale
float = 1.0
The scaling factor (width) of the output range.
translation
float = 0.0
The lower bound (minimum value) of the output range.
columns
list of int
Indices of columns to transform. If None, transforms all columns.

Attributes

min_
np.ndarray of shape (n_selected_columns,)
Per-column minimum observed in the training data.
max_
np.ndarray of shape (n_selected_columns,)
Per-column maximum observed in the training data.
range_
np.ndarray of shape (n_selected_columns,)
Per-column range (:math:`max - min`) observed in the training data.

Notes

When to use:
  • When you need features to be in a specific range (e.g., [0, 1] for neural networks).
  • When you want to preserve zero entries in sparse data.
  • When features do not follow a Gaussian distribution.
Limitations:
  • Highly sensitive to outliers, as they can significantly squash the inliers.

Scale features to the [0, 1] range:

python
>>> from tuiml.preprocessing.scaling import MinMaxScaler
>>> import numpy as np
>>> X = np.array([[1, 2], [3, 4], [5, 6]])
>>> normalizer = MinMaxScaler()
>>> X_norm = normalizer.fit_transform(X)
>>> print(X_norm.min(axis=0), X_norm.max(axis=0))
[0. 0.] [1. 1.]

Methods

get_parameter_schema (cls)
fit (self, X: np.ndarray, y: Optional[np.ndarray]=None, feature_names: Optional[List[str]]=None) -> 'MinMaxScaler'
transform (self, X: np.ndarray) -> np.ndarray
inverse_transform (self, X: np.ndarray) -> np.ndarray
__repr__ (self) -> str