liveBook · Manning

Label encoding

Also called ordinal encoding

Label encoding is a categorical-data transformation that maps each category to a numerical code, which may imply an ordering among categories.

How 4 Manning books explain it

Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

Ordinal encoding represents categorical values with integer codes that impose an ordered numerical representation.

How it is used
Prepares categorical predictors as numeric inputs for machine-learning pipelines and categorical relationship analysis.
How deep it goes
Defines arbitrary numeric category assignment and compares model suitability, cardinality limits, and pipeline configuration.
Examples
Uses Airbnb neighbourhood, accommodation type, room type, and coordinates features in ColumnTransformer pipelines.
What you can do after
Apply it via scikit-learn OrdinalEncoder and ColumnTransformer when configuring categorical feature pipelines.

Read how Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI explains label encoding →

Grokking AI Algorithms, Second Edition

Label encoding maps each category to a numerical label, typically an integer in a fixed range.

How it is used
Converts categorical features into numerical values for statistical modeling.
How deep it goes
Defines label encoding and contrasts it with one-hot encoding, including an explanation of unintended bias.
Examples
Uses diamond cut and origin categories, plus a parking scenario with scalar-encoded goals and obstacles.
What you can do after
Evaluate whether label encoding or one-hot encoding better suits a categorical feature.

Read how Grokking AI Algorithms, Second Edition explains label encoding →

Ensemble Methods for Machine Learning

Ordinal encoding maps each category of a categorical variable to a single numeric value, optionally preserving an inherent category order.

How it is used
Converts categorical features into numeric inputs before training machine-learning models.
How deep it goes
Defines mappings, demonstrates explicit category orders, and stops short of detailed encoding internals.
Examples
Uses color and size mappings, an explicit OrdinalEncoder configuration, encoded arrays, and ensemble comparisons.
What you can do after
Apply it via scikit-learn's OrdinalEncoder and compare its model performance against alternative encodings.

Read how Ensemble Methods for Machine Learning explains label encoding →

Outlier Detection in Python

Ordinal encoding is a categorical encoding technique that maps discrete categories to integer codes representing an order.

How it is used
Prepares categorical features for numeric outlier detectors when mixed data cannot be processed directly.
How deep it goes
Explains integer mapping and detector-specific behavior, but stops short of prescribing one universally best encoding.
Examples
Uses Color mappings, Department frequencies, and categorical bins in HBOS to demonstrate representation and detector effects.
What you can do after
Apply ordinal encoding when preparing categorical features for compatible unsupervised outlier detectors.

Read how Outlier Detection in Python explains label encoding →

Also covered in

What to know first

Related concepts

Questions about label encoding

What is label encoding?

Label encoding is a categorical-data transformation that maps each category to a numerical code, which may imply an ordering among categories.

Which Manning books explain label encoding?

Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI, Grokking AI Algorithms, Second Edition, Ensemble Methods for Machine Learning and Outlier Detection in Python.

What should I know before learning label encoding?

Manning books that teach label encoding usually introduce categorical data, gradient boosting, one-hot encoding and binary variable first.

What is the difference between label encoding and one-hot encoding?

Label encoding is a categorical-data transformation that maps each category to a numerical code, which may imply an ordering among categories. One-hot encoding represents a categorical value as a binary vector with one active component identifying its category and all other components inactive.

What is label encoding a kind of?

Label encoding is a kind of encoding. Encoding is the process or scheme of mapping information into a different representation according to defined rules for storage, processing, transmission, or interpretation.

What is label encoding also called?

Label encoding is also called ordinal encoding.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.