Feature Scaling: Min-Max Normalization

Min-Max Normalization rescales numeric features to a fixed range (typically [0, 1]) by mapping the minimum to 0 and the maximum to 1. This ensures that no single feature dominates due to scale differences, which is critical for distance-based and gradient-based algorithms.


The Min-Max Formula

For each value x in a feature column: x' = (x − x_min) / (x_max − x_min). The result is always in [0, 1], preserving the shape of the distribution while compressing its range.

Applying MinMaxScaler

<pre><code class="language-python">from sklearn.preprocessing import MinMaxScaler scaler = MinMaxScaler(feature_range=(0, 1)) X_train_scaled = scaler.fit_transform(X_train) X_test_scaled = scaler.transform(X_test) # use training min/max! print(X_train_scaled.min(axis=0)) # all zeros print(X_train_scaled.max(axis=0)) # all ones</pre>

When to Use Min-Max vs Standardization

Min-Max normalization is preferred when the data has a bounded range or when the algorithm expects inputs in [0, 1] (e.g., neural networks with sigmoid activations, image pixel values). It is sensitive to outliers, which can crush most values near zero or one.

Sensitivity to Outliers

A single outlier at 1,000,000 in an otherwise [0, 100] feature will compress all normal values to near zero after scaling. Apply outlier treatment (capping or removal) before min-max scaling, or use RobustScaler which uses percentiles instead of extremes.

<pre><code class="language-python">from sklearn.preprocessing import RobustScaler scaler = RobustScaler() # uses median and IQR — robust to outliers X_train_scaled = scaler.fit_transform(X_train)</pre>