2
$\begingroup$

Usually if I have regression problem and my initial dataset contains categorical variables like :

column 1:  
Math
Science 
Science 
English 

I would convert this non-numerical variables to numerical variable such that : Math: 0, Science : 1, English : 2. However, I recently found a tutorial said that this solution is not performant because there is no favorite class among other means there is no increase between those classes and if it existe we can not quantify it.

Can anyone explain this for me because I usually worked with solution one ?

$\endgroup$
2
$\begingroup$

This solution would be performant only if your values has an order. Some models use as learning function the distance between points, and if you use your method, a student in Math and a student in English (0 and 2 making a 2 distance) will have more distance than a student in Math and a student in Science (0 and 1 making a 1 distance). Using this method involves a bias, so you'll have to go another way. One well known method is One Hot Encoding, which will create 3 binary-variables Column1_Math, Column1_Science, Column1_English, with values 0 or 1 (for example, if column 1 is Math, then you'll have Column1_Math = 1, Column1_Science = 0, Column1_English = 0). This way, you avoid biaising your model.

I already explained other ways I know to deal with your issue in this answer that I highly suggest you to take a look at

$\endgroup$
3
  • 1
    $\begingroup$ Yes I got the point but what if I have three categorical columns and each one has 10 different value so I will create 30 new columns? $\endgroup$ – baddy Aug 26 '20 at 15:36
  • 1
    $\begingroup$ That's why you have other ways to deal with this issue than OHE. You can for example manually regroup categories to make them from 10 values to 3 for example, or use a Target Encoder / Category Encoder. You should check the link I posted, I explained a bit more there. $\endgroup$ – BeamsAdept Aug 27 '20 at 6:51
  • 2
    $\begingroup$ ok It is clear Thank you very much $\endgroup$ – baddy Aug 27 '20 at 7:29

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.