0
$\begingroup$

Suppose my Dataset for automobiles has a feature 'Number of cylinders' with labels 'One','Two'..(Strings) as categories,what should be preferred label encoding or One hot encoder?

$\endgroup$

1 Answer 1

1
$\begingroup$

In your specific case 'Number of cylinders' is a discrete numerical variable not a categorical variable.

In general for categorical variable you can use label encoding if the levels of your categorical variable are somehow ordered (e.g. volume: small, medium, big) otherwise it is better to use one hot encoding.

$\endgroup$
4
  • $\begingroup$ In my case 'One','Two,,etc are string variables and not numerical,But I can see the confusion in question.Thats why i mentioned in quotes.Let me edit the question. $\endgroup$ Commented Nov 20, 2019 at 16:48
  • $\begingroup$ Generally One Hot Encoder is preferred to Labels as One Hot Encoder gives new columns with binary values which is easily understood by most algorithms.But I am asking in case of regression explicitly $\endgroup$ Commented Nov 20, 2019 at 16:53
  • 1
    $\begingroup$ That you elect to record actual numbers 1, 2, 3, etc. as strings does not change their meaning--it only makes it more difficult for you to analyze them appropriately. One might still treat them as categorical or nominal variables in a model--but that's a modeling decision and it should not be determined solely by the physical data type or the conceptual data type. $\endgroup$
    – whuber
    Commented Nov 20, 2019 at 16:56
  • $\begingroup$ The downside of one hot encoding in your case is that you lose information ( 3 cylinders > 2 cylinders > 1 cylinder). If this info is useful I would go for label encoding. $\endgroup$ Commented Nov 20, 2019 at 16:58

Your Answer

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

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