Why do we need one-hot encoding?

Categorical variables must be encoded before they can be used as features to train a machine learning model. There are various encoding techniques, including:

  • One-hot encoding
  • Label encoding
  • Ordinal encoding
  • Target encoding

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.

Speak Your Mind