liveBook · Manning

OrdinalEncoder

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

OrdinalEncoder is a scikit-learn transformer that maps categories to numeric ordinal codes.

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

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Defines ordinal transformation and compares model fit, but stops short of implementation syntax or parameter details.
Examples
Uses categorical strings, high-cardinality IDs, ZIP codes, product names, and geographical names as encoding examples.
What it assumes
Assumes categorical features and machine-learning algorithms, while defining encoding and distinguishing it from embeddings.
What you can do after
Evaluate whether ordinal encoding suits a categorical feature and a tree-based model, especially under high cardinality.
How it connects
Contrasts with OneHotEncoder, LabelEncoder, embeddings, and target encoding, and relates to random forests and gradient-boosted decision trees.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.