liveBook · Manning

Categorical encoding

As explained in Outlier Detection in Python

Categorical encoding is the transformation of categorical values into numerical representations suitable for computational analysis.

Categorical encoding transforms categorical values into numerical representations so numeric analysis and outlier detectors can process them. section 4.9 section 9.0

Common encoding choices include:

  • Ordinal encoding maps each category to a number, such as Red → 0, Blue → 1, and Green → 2. section 4.9
  • Count encoding replaces each category with its frequency, so Red, Blue, and Green become 3, 2, and 1. section 4.9
  • One-hot encoding replaces a categorical column with one binary column per unique value. section 4.9

Encoding baseball positions

Applying one-hot encoding to a baseball position column creates features such as Position_Catcher, Position_First_Base, and Position_Outfield. Each row receives one 1 for its position and 0 in the other position columns, while existing numeric features remain unchanged. section 4.9

df = pd.get_dummies(df)

Use pandas to replace categorical columns with binary indicator columns while retaining numeric features. section 4.9

How Outlier Detection in Python covers it

How deep it goes
Defines ordinal, count, and one-hot methods with concrete mappings, but defers fuller method discussion.
Examples
Uses color mappings and baseball position indicators to demonstrate ordinal, count, and one-hot representations.
What it assumes
Assumes categorical columns and numeric detector requirements, while introducing the main encoding choices from basic examples.
What you can do after
Apply it via pandas get_dummies to convert categorical dataframe columns into binary features.
How it connects
Connects categorical encoding with outlier detection, preprocessing, missing-data handling, scaling, binning, and ensemble diversity.

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 Outlier Detection in Python. The section links point to the parts of the book it draws on.