0
$\begingroup$

I am aware of the practice that label encoding is preferred for ordinal variables while one-hot encoding is done for nominal variables. But what if we label encode nominal variables? Will it have any negative impact on modeling or prediction?

For eg -

>>> data['Card_Category'].unique()
... array(['Blue', 'Gold', 'Silver', 'Platinum'], dtype=object)
>>> card_mapping = {'Blue': 0, 'Gold': 1, 'Silver': 2, 'Platinum': 3}
>>> data['Card_Category'].replace(card_mapping, inplace=True)

Instead of using one-hot encoding, I have used label encoding. Thoughts on this?

$\endgroup$
4
  • 1
    $\begingroup$ Where does this practice come from? I can't think of an algorithm that would internally treat labels differently from one-hot encoding. Actually (my guess, since I haven't seen all the source code) I believe labels are internally translated into one-hot encoding (or dummy variables, but to the same effect). So it should make no difference for you. However, neither of these is actually advisable for ordinal variables, as you lose the information about the relationship between the values. $\endgroup$
    – Igor F.
    Commented Jan 6, 2021 at 9:05
  • $\begingroup$ @IgorF. Can you elaborate on the part Algorithms internally treat labels as one-hot encoding ? $\endgroup$ Commented Jan 6, 2021 at 9:14
  • $\begingroup$ See e.g.: datascience.stackexchange.com/q/77880/55122 , stats.stackexchange.com/q/411767/232706 , stats.stackexchange.com/q/410939/232706 , As for implementations as @IgorF. addresses, it depends. See e.g. datascience.stackexchange.com/a/87403/55122 $\endgroup$ Commented Jan 6, 2021 at 21:10
  • $\begingroup$ @BenReiniger OK, thanks, I think I misinterpreted the question. @AmitPathak Sorry, I'm not an expert on sklearn implementation. $\endgroup$
    – Igor F.
    Commented Jan 6, 2021 at 21:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.