When scaling matters
Linear models, distance-based models (kNN, k-means), and neural networks need scaled features. Tree-based models do not — they only care about ordering. Use StandardScaler for symmetric distributions, RobustScaler when outliers are present, and MinMaxScaler when bounded inputs are required (some neural nets, image pipelines).
Encoding categoricals
- One-hot for low-cardinality (under ~30 categories), works with any model.
- Ordinal when the order is meaningful and the model is tree-based.
- Target encoding when cardinality is high and the model is tree-based; always apply inside CV folds.
- Hashing when memory is the constraint and you can tolerate collisions.
Pipeline placement
Scalers and encoders belong inside the pipeline, fit on training only, applied to validation and production identically. Keep the column transformer as the single entrypoint for raw rows; never preprocess in a notebook cell that is not in the pipeline.