NEW
Also known as: Integer Encoding, Ordinal Encoding
Technique that maps categorical values to integer codes for model consumption.
DESCRIPTION
Label encoding converts categories to integers, typically for target labels or ordinal features. For nominal features, using label encoding can mislead models by introducing artificial order. It is efficient and compact but may cause issues with tree splits or linear models when applied to unordered categories. One-hot encoding avoids ordinal assumptions but increases dimensionality. Proper encoding choice depends on feature semantics and model type.
ALTERNATIVE DEFINITIONS
scikit-learn
Encode target labels with value between 0 and n_classes-1.
Explicitly focuses on target label encoding rather than feature encoding.
scikit-learn
Encode categorical features as an integer array.
Describes integer encoding for features, clarifying use beyond labels.
RELATED TERMS
Feature Engineering Categorical Data Preprocessing Dummy Variables Embeddings
COMPETING TERMS
One-Hot Encoding Target Encoding
RELATIONS
- Broader: Encoding
KNOWLEDGE AREAS
Data Science AI Data Engineering Data Modeling
TARGET AUDIENCE
Data Scientist AI Engineer Analytics Engineer Data Engineer
EXTERNAL SOURCES
- Wikipedia - Categorical variable
- scikit-learn - Guide on categorical encoding
- category_encoders - Ordinal encoding documentation
TOP QUESTIONS
What is Label Encoding and when is Label Encoding appropriate?
Label encoding maps categories to integers. Use it for target labels or truly ordinal features; avoid for nominal features to prevent spurious ordinal relationships.
Category: Overview
What is a common mistake with Label Encoding?
Applying it to nominal features introduces artificial order, misleading distance-based and linear models.
Category: Mistakes
What risks arise from Label Encoding?
Models may learn order where none exists, causing biased splits or incorrect coefficient interpretations.
Category: Risks
What competing techniques exist to Label Encoding?
One-hot encoding for nominal features and target encoding for high-cardinality categories are common alternatives.
Category: Alternatives
How does Label Encoding affect tree-based models?
Trees can split on integer thresholds, potentially imposing false order. One-hot often yields clearer splits for nominal categories.
Category: Opinion
Is Label Encoding suitable for neural networks?
Use embeddings or one-hot for nominal categories. Label-encoding alone can be suboptimal for learned representations.
Category: Requirements
How to handle unseen categories with Label Encoding?
Fit encoders on training data and map unknowns to a dedicated code or use encoders supporting handle_unknown.
Category: BestPractice
How does Label Encoding compare to One-Hot Encoding?
Label encoding is compact but orders categories; one-hot prevents ordering but increases dimensionality.
Category: Misunderstanding
What preprocessing steps complement Label Encoding?
Clean categories, consolidate rare values, and consider frequency encoding or target encoding for high-cardinality features.
Category: HowTo