Why do we need one-hot encoding?
Classic MLLevel: IntermediateClassification
Why do we need one-hot encoding?
Hints
- State the task, inputs and prediction target.
- Compare with a simple baseline: assumptions, objective and independent validation.
Answer
If we simply encode categorical variables with a Label encoder, they become ordinal which can lead to undesirable consequences. In this case, linear models will treat category with id 4 as twice better than a category with id 2. One-hot encoding allows us to represent a categorical variable in a numerical vector space which ensures that vectors of each category have equal distances between each other. This approach is not suited for all situations, because by using it with categorical variables of high cardinality (e.g. customer id) we will encounter problems that come into play because of the curse of dimensionality.
Source and licence: Alexey Grigorev & contributors — Data Science Interviews · CC-BY-4.0