2
$\begingroup$

I have a categorical variable that measures the income of a family:

A: no income
B: Up to $500
C: $500-$700
…
P: $5000-$6000
Q: More than \\\$6000

It seems odd to me that I have to get dummies for this variable, since it's ordered. I wonder if it's better to map the values: {'A': 0, 'B': 1, …, 'Q': 17} so I can input it into the algorithm this values as integer numbers.

What's the proper way of preprocessing this variable to feed an algorithm such as Random Forest or a simple neural network?

$\endgroup$
  • $\begingroup$ I have come across "ordinal classification" algorithms, such as ordinal SVM. I suppose those libraries have their own input suggestions. Unfortunately, I am not aware of one at the moment. The next best thing I believe would be to do a regression. $\endgroup$ – Grzegorz Aug 20 at 21:01
0
$\begingroup$

One way to do is to use target encoding:

(There are a million resources to learn target encoding)

This way your categories will not only be ordered by the number but for the target value (what is at the end what you want, to give better predictions)

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.