Skip to content
E
Educatum

Standardization VS Normalization

Curated by Educatum AI teamLast updated:
Basic Concepts
Direct Answer

Standardization (z-score scaling) centers each feature to zero mean and unit variance, while normalization (min-max scaling) rescales features into a fixed interval such as [0, 1]. Standardization is generally preferred for gradient-based models, SVMs, and PCA because it preserves zero-centered distributions and handles moderate outliers better, whereas normalization is useful when bounded inputs like image pixels are explicitly required.

Study Card: Standardization vs. Normalization

Direct Answer

Standardization and normalization are feature scaling transformations applied independently per feature:

xstd=x−μσ,xnorm=x−xmin⁡xmax⁡−xmin⁡x_{\text{std}} = \frac{x - \mu}{\sigma}, \qquad x_{\text{norm}} = \frac{x - x_{\min}}{x_{\max} - x_{\min}}
  • Standardization (Z-score scaling) shifts data to mean 00 and standard deviation 11 without imposing hard bounds. It is the default choice for linear/logistic regression with regularization, SVMs, KNN, K-means, PCA, and neural networks (where zero-centered, unit-variance inputs align with standard initialization schemes and well-conditioned loss landscapes).
  • Normalization (Min-Max scaling) maps values linearly into a bounded interval (typically [0,1][0, 1] or [−1,1][-1, 1]). It is useful when an algorithm or input domain specifically expects bounded inputs—such as pixel intensities in [0,1][0, 1]—but is highly vulnerable to outliers because a single extreme minimum or maximum compresses all remaining values into a narrow band.

Always fit scalers exclusively on the training split (fit_transform(X_train)) and apply those saved parameters to validation/test data (transform(X_test)) to prevent data leakage.

Key Terms

  • Feature Scaling: Aligning feature magnitudes so optimization and distance metrics treat features comparably.
  • Standardization (Z-score): Subtracting the training feature mean μ\mu and dividing by the training standard deviation σ\sigma.
  • Normalization (Min-Max Scaling): Rescaling features by range xmax⁡−xmin⁡x_{\max} - x_{\min} into [0,1][0, 1] (or [a,b][a, b]).
  • Outliers: Extreme observations; min-max scaling pins the entire scale to extreme min/max values, while standardization still shifts μ\mu and inflates σ\sigma under severe outliers (motivating RobustScaler using median and IQR).
  • Data Leakage: Accidentally using validation/test statistics when computing scaling parameters.

Example

Consider features age (20 to 80) and income (USD 30,000 to USD 300,000). In Euclidean-distance models like KNN or K-means, raw income differences dominate age differences by orders of magnitude unless both are scaled. Now suppose one individual has an outlier income of USD 1,000,000: min-max normalization maps USD 1,000,000 to 1.0 and compresses almost everyone else near [0.0, 0.28]. Standardization is also shifted by the outlier (since μ\mu rises and σ\sigma grows), but avoids hard [0,1][0, 1] compression—and when heavy outliers are expected, RobustScaler (median/IQR) resists extreme values altogether.

Code Implementation

import numpy as np
from sklearn.preprocessing import StandardScaler, MinMaxScaler

# Sample data with different feature scales
data = np.array([[1, 1000], [2, 2000], [3, 3000], [4, 4000], [5, 5000]])

# Standardization (zero mean, unit variance)
std_scaler = StandardScaler()
data_standardized = std_scaler.fit_transform(data)
print("Standardized Data:\n", data_standardized)

# Normalization (min-max to [0, 1])
minmax_scaler = MinMaxScaler()
data_normalized = minmax_scaler.fit_transform(data)
print("\nNormalized Data:\n", data_normalized)

# Illustrative example with a large outlier in feature 2
data_with_outlier = np.array([[1, 10], [2, 20], [3, 30], [4, 1000]])

standardized_with_outlier = StandardScaler().fit_transform(data_with_outlier)
print("\nStandardized data with outlier:\n", standardized_with_outlier)

normalized_with_outlier = MinMaxScaler().fit_transform(data_with_outlier)
print("\nNormalized data with outlier:\n", normalized_with_outlier)
  • Tree-Based Models vs. Scale-Sensitive Models: Decision trees, Random Forests, and XGBoost/LightGBM partition features monotonically via thresholds and are invariant to monotonic feature scaling, whereas linear models, SVMs, KNN, K-means, PCA, and neural networks require scaling.
  • RobustScaler: Uses median and interquartile range (IQR), providing stronger outlier resistance than both StandardScaler and MinMaxScaler.
  • Gradient Descent Conditioning: Scaling features onto comparable magnitudes avoids elongated elliptical loss contours, allowing larger stable learning rates and faster convergence.
  • Train/Test Splitting Hygiene: Using sklearn.pipeline.Pipeline automatically ensures fit_transform runs only inside training folds during cross-validation.
View all →

Try keywords like RoPE, FlashAttention, DPO, or Blind 75.