Many algorithms are sensitive to the scale of features — a column measured in thousands will dominate one measured in fractions. Scaling puts every feature on a comparable range so the model weighs them fairly.
Standard vs MinMax
from sklearn.preprocessing import StandardScaler, MinMaxScalerscaler = StandardScaler() # mean 0, std 1 (z-score)X_train_s = scaler.fit_transform(X_train) # FIT on trainX_test_s = scaler.transform(X_test) # only TRANSFORM test# MinMaxScaler squashes to [0, 1] instead
Which models need it?
Key takeaways
- 01Scaling puts features on a comparable range so none dominates by unit alone.
- 02StandardScaler → mean 0, std 1; MinMaxScaler → [0, 1].
- 03Fit the scaler on training data, then transform both train and test.
- 04Distance/gradient models (KNN, SVM, PCA, k-means) need scaling; tree models don't.
