--- name: feature-engineering description: Use when creating, encoding, scaling, or selecting features for ML models. Covers categorical encoding, numeric transforms, datetime/text/aggregation features, and leakage-safe target encoding. --- # Feature Engineering ## Overview Feature engineering is where most model performance is won or lost. The aim is to express the signal in a form the model can use, while never letting information from the target or the test set leak into a feature. ## When to use - After cleaning, before/iterating with modeling. - A model plateaus and you suspect under-expressed signal. - You have raw datetime, text, or relational data to turn into columns. ## Encoding categoricals | Cardinality | Encoder | Notes | |-------------|---------|-------| | Low (<15), tree model | One-hot or native categorical | LightGBM/CatBoost handle natively | | Low, linear model | One-hot | Drop-first to avoid collinearity | | High (>15) | Target/leave-one-out encoding | **Must** be cross-fitted to avoid leakage | | Ordinal meaning | Ordinal map | Preserve order (low