target_encode
Transform high-cardinality categorical columns into smoothed target means, enabling better model performance. Use on training data after splitting to prevent leakage.
Instructions
Target-encode high-cardinality categorical columns. Each category is replaced by the smoothed mean of the target variable. Good for columns with many unique values. Best for high-cardinality (>10 categories). IMPORTANT: to avoid data leakage, split data first with train_test_split, then encode training set only. Example: target_encode(columns=["AgentCode","OriginCode"], target_column="Log_Revenue", smoothing=10.0)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| columns | Yes | ||
| df_name | No | ||
| smoothing | No | ||
| target_column | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |