NEW
Technique representing categorical values as binary indicator vectors with exactly one active position per category.
DESCRIPTION
One-hot encoding transforms categorical features into vectors of zeros and ones, enabling algorithms to process non-numeric labels. It prevents unintended ordinal relationships present in label encoding. Implementations provide dense or sparse outputs and handle unknown categories via explicit flags. High-cardinality features can cause dimensionality explosion, requiring hashing or target encoding alternatives. Commonly used in tabular ML, NLP token representation, and deep learning input preparation.
ALTERNATIVE DEFINITIONS
scikit-learn
Encode categorical features as a one-hot numeric array.
Concise tool-focused definition emphasizing numeric output.
TensorFlow
Converts a class vector (integers) to binary class matrix.
Provides the encoding operation within Keras utilities.
RELATED TERMS
Categorical Data Dummy Variables Sparse Matrix Feature Engineering OneHotEncoder Cardinality Hashing Trick scikit-learn
COMPETING TERMS
Label Encoding Target Encoding
RELATIONS
- Broader: Encoding
KNOWLEDGE AREAS
TARGET AUDIENCE
Data Scientist AI Engineer MLOps Engineer Analytics Engineer
EXTERNAL SOURCES
- Wikipedia - One-hot
- Pandas - get_dummies for one-hot-like encoding
- scikit-learn - Guidance on encoding categorical features
TOP QUESTIONS
Why use One-hot Encoding instead of Label Encoding?
One-hot Encoding prevents artificial ordinal relationships that can mislead models, especially linear or distance-based algorithms.
Category: Relevancy
What’s the risk of One-hot Encoding with high-cardinality features?
It can create huge sparse vectors, increasing memory, compute, and overfitting risk.
Category: Risk
How do you manage dimensionality from One-hot Encoding?
Use hashing, grouping rare categories, dimensionality reduction, or alternative encoders like target encoding.
Category: Management
Is One-hot Encoding always sparse?
It can be represented sparsely for efficiency; some libraries default to sparse matrices.
Category: Misunderstanding
Where is One-hot Encoding most useful?
Tabular ML, text token indices, and categorical inputs for neural networks benefit from one-hot representations.
Category: Application
How to handle unknown categories in One-hot Encoding?
Configure encoders to ignore, raise errors, or use an ‘unknown’ bucket.
Category: Requirements
Does One-hot Encoding suit tree-based models?
Trees often perform well with label encoding; one-hot may still help with interactions or certain split behaviors.
Category: Opinion
What is the biggest mistake with One-hot Encoding?
Encoding high-cardinality features without mitigation can explode feature space and harm generalization.
Category: Mistakes
How does One-hot Encoding interact with regularization?
L1 regularization can encourage sparsity by dropping unnecessary indicators; L2 can stabilize weights across many dummy variables.
Category: Example