Learn Before
Example
One-Hot Encoding of Categorical Features Example
To prepare discrete categorical features for machine learning models, they are often transformed using one-hot encoding. For instance, consider a categorical feature like 'MSZoning' that assumes the values 'RL' and 'RM'. By dropping the original 'MSZoning' feature, two new indicator features (or dummy variables) are created: 'MSZoning_RL' and 'MSZoning_RM', which take values of either or . If an example's original value for 'MSZoning' is 'RL', then its 'MSZoning_RL' feature is set to and its 'MSZoning_RM' feature is set to .
0
1
Updated 2026-05-07
Tags
D2L
Dive into Deep Learning @ D2L