Skip to main content
Albero Academy

Feature Scaling

Put features on the same scale so models treat them fairly.

Preprocessing9 min

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

the two common scalers
from sklearn.preprocessing import StandardScaler, MinMaxScaler
scaler = StandardScaler() # mean 0, std 1 (z-score)
X_train_s = scaler.fit_transform(X_train) # FIT on train
X_test_s = scaler.transform(X_test) # only TRANSFORM test
# MinMaxScaler squashes to [0, 1] instead

Which models need it?

Key takeaways

  1. 01Scaling puts features on a comparable range so none dominates by unit alone.
  2. 02StandardScaler → mean 0, std 1; MinMaxScaler → [0, 1].
  3. 03Fit the scaler on training data, then transform both train and test.
  4. 04Distance/gradient models (KNN, SVM, PCA, k-means) need scaling; tree models don't.

Finished this chapter?

Mark it complete to track your progress through Scikit-learn.