liveBook · Manning

Categorical encoding

As explained in Machine Learning System Design

One-hot encoding is a representation technique that converts a categorical value into a vector with one active indicator for its category.

Categorical encoding transforms category-valued features into representations that machine-learning models can process. One-hot encoding is one option; ordinal encoding, mean target encoding, and the hashing trick provide alternatives for different data shapes and risks. section 11.1.2

Use the encoding choice to match the modeling pipeline:

  • Apply one-hot encoding as basic feature engineering, including before a logistic regression model. section 10.1.1
  • Consider ordinal encoding when categories have an inherent order, or the hashing trick for large-scale categorical data. section 11.1.2
  • Treat mean target encoding cautiously because using target information can introduce data leakage. section 11.1.2

From feature engineering to a model

A simple logistic-regression system can combine feature scaling, one-hot encoding, and model inference as an ordered pipeline. In a larger ETA system, categorical and other tabular features may instead become discrete tokens and learnable embeddings for a transformer. section 10.1.1 section 11.1.2

Figure 11.1 An overview of the DeepETA model pipeline: example of combining base feature engineering and a deep learning model (source: https://mng.bz/0MoN)
figure

Inspect the DeepETA pipeline to see how base feature engineering connects categorical and other inputs to a deep learning model. section 11.1.2

How Machine Learning System Design covers it

How deep it goes
Compares encoding methods and flags leakage risk, but does not detail vector construction or implementation steps.
Examples
Uses logistic regression preprocessing and Uber’s DeepETA pipeline as concrete examples.
What it assumes
Assumes familiarity with categorical features and machine-learning pipelines, while positioning encoding as basic preprocessing.
What you can do after
Apply it within a model pipeline and select alternatives while avoiding target leakage.
How it connects
Connects categorical encoding with feature engineering, preprocessing pipelines, embeddings, and transformer architecture.

Also explained in

Compare how 13 books explain categorical encoding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning System Design. The section links point to the parts of the book it draws on.