In Spark MLlib, what is the difference between Normalizer and StandardScaler?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Normalizer works per row — it scales each data point so its feature vector has length 1. StandardScaler works per column — it centers and scales each feature across the whole dataset. Different axes, different use cases.
Full explanation below image
Full Explanation
Normalizer(inputCol='features', outputCol='norm_features', p=2.0) — L2 normalization: scales each sample's feature vector so its L2 norm = 1. Use case: text classification (makes document length irrelevant), SVM, cosine similarity-based algorithms. Does NOT require fitting — it's a Transformer (no fit step), just divides each row by its norm. StandardScaler(inputCol='features', outputCol='scaled_features', withMean=True, withStd=True) — column-wise: computes per-column mean and standard deviation from training data (Estimator that produces a Transformer). Scales each feature to: (x - mean) / std. Use case: linear models, neural networks, k-nearest neighbors, PCA. Use StandardScaler when features are on different scales (age 0-100, income 0-1M). Use Normalizer when comparing data points by cosine similarity or when using algorithms that rely on vector magnitude.