OrdinalEncoder converts categorical string values into ordered numeric codes so machine-learning algorithms can process them. It is especially suitable for complex tree-based models such as random forests and gradient-boosted decision trees, which can split the coded feature into useful partitions. section 6.1.3
Choose ordinal encoding with these trade-offs in mind:
- Prefer one-hot encoding for many linear and tree-based modeling cases when categories are manageable. section 6.1.3
- Treat high-cardinality features such as IDs, ZIP codes, product names, and geographical names cautiously: ordinal codes may not form meaningful tree partitions. section 6.1.3
- Consider target encoding for high-cardinality categoricals when one-hot and ordinal representations create modeling or memory problems. section 6.1.3
