Which categorical encoding for models other than linear and tree-based mdoels

Hi,

in the notebook Encoding of categorical variables you state that

Thus, in general OneHotEncoder is the encoding strategy used when the downstream models are linear models while OrdinalEncoder is used with tree-based models .

which is very good advice! But I wonder, which encoding strategy should be used for nonlinear, non-tree based models such as Neural Networks or GAMs? Am I right to suspect that OneHotEncoder should be used, unless the the original categories (before encoding) have an ordering, i.e., the same strategy as for linear models? Thanks!

Yes, you are right. OneHotEncoder should generally be used in these cases. Indeed, OrdinalEncoder would be a good default only for tree-based models. In this MOOC, we are presenting only linear and tree-based models; it explains why we did not make a more complex statement. However, we could consider being more explicit with some additional information for predictors that do not fit in these categories.

1 Like

Thanks for the answer! Mine was not a criticism - in the context of the MOOC, it makes sense to focus only on the predictors you’re going to talk about. But I wanted to know more, so I took the opportunity to ask here :slightly_smiling_face:

We also accept criticism to improve the content :slight_smile:

1 Like