Label encoding
Label encoding is a categorical-data transformation that maps each category to a numerical code, which may imply an ordering among categories.
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 rating-related categorical features into numeric inputs for statistical models.
- How deep it goes
- Defines numeric labels and explains when to choose them over one-hot encoding, without giving an implementation workflow.
- Examples
- Contrasts diamond Cut ratings with unranked Origin values and compares them with reward-valued neural-network inputs.
- What you can do after
- Practice/perform categorical data preparation by labeling ratings and choosing one-hot encoding for categories without a ranking.
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 →
Related concepts
- categorical encodingkind of · Categorical encoding transforms discrete category values into numerical representations, such as separate binary indicators or vectors with one active position per category.
- one-hot encodingalternative to · One-hot encoding represents each category as a binary vector or set of indicators with exactly one active component identifying that category.
- OrdinalEncoderused by · OrdinalEncoder is a scikit-learn transformer that maps categorical feature values to integer codes representing their ordered categories.
- scikit-learnused by · scikit-learn is an open-source Python library providing tools for classical machine learning, including algorithms, preprocessing, model selection, and evaluation.
- biasproduces · Bias is a systematic deviation or tendency in data, measurements, estimates, judgments, or outputs that skews them relative to a relevant target or impartial baseline.
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.



