0
votes

I have a dataset with non-ordinal categorical features. What is the best way to transform them (encoding + scaling) before training the machine learning model (Linear SVC)?

Things I tried:

  1. Label Encoding - This works. But scaling doesn't make sense as different categories in a feature don't have any specific order.

  2. One-Hot encoding - There are thousand's of unique categories in a features, which is making the ML model complex by creating thousands of columns.

  3. Count encoding - My train-test split didn't have all unique categories of a feature in the training set, which introduces NaN's in test set when I count-encode those features.

Appreciate your help!

1

1 Answers

0
votes

To tackle your problem of having some unique values in the test set that are not in the training set, you can try to do the following :

  1. Merge the training dataset using df = train.append(test)
  2. Apply the encodings that you have used earlier
  3. Split the datasets back into train and test using :
  • train = df.head(len(train))

  • test = df.tail(len(test))

Based on my experience I can say that LabelEncoding and OneHotEncoding are some of the best techniques to encode non-ordinal features.

Hope this was helpful :)