Why Scale Features? — Interview Answer — ML Technical Interview Questions & Answers
Model answer covering distance-based algorithms.
Why Scale Features? — Interview Answer
- Say this: “Scaling puts features on a similar range so distance and gradient methods don’t treat fees 80000 as more important than hours 8. I fit the scaler on train and transform test.”
- Need it: KNN, SVM, logistic (helps), PCA, gradient descent nets. Trees: usually optional (splits don’t care about units).
- StandardScaler (mean 0, std 1) or MinMax 0–1. Pipeline it.
- Trap: scaling with test statistics. Trap: scaling dummy 0/1 and tree-only pipelines as if it were mandatory without explanation.
Technical Interview Tip: KNN/SVM/PCA: scale. Fit on train. Trees can skip.
Code Examples for Why Scale Features? — Interview Answer
Why Scale Features? — Interview Answer — working example
xs = [10, 20, 30, 40]
mean = sum(xs) / len(xs)
var = sum((x - mean) ** 2 for x in xs) / len(xs)
std = var ** 0.5
z = [(x - mean) / std for x in xs]
lo, hi = min(xs), max(xs)
minmax = [(x - lo) / (hi - lo) for x in xs]
print([round(v, 3) for v in z])
print(minmax)
# sklearn.preprocessing.StandardScaler fits mean/std on train onlyWhy Scale Features? — Interview Answer — scaling keeps features comparable — critical for distance-based models and many optimizers.
How to Explain Why Scale Features? — Interview Answer to an Interviewer
Why scale?
Distance and gradients Units differ
Which models need it most?
KNN SVM PCA GD nets