2
$\begingroup$

For a nominal categorical variable that has two levels, e.g. Gender (levels = Male,Female), is it feasible to use label encoding instead of One Hot encoding ? If it is, are there any implications of using one encoding method over the other, for such a categorical variable ?

$\endgroup$
1
$\begingroup$

If you use one-hot here, you're just adding an unnecessary variable that is perfectly correlated with another variable in your model. Rather than thinking of it as a label encoding of gender where "0=male, 1=female", think of it as a binary flag for is_female, where "0=false, 1=true".

$\endgroup$
2
  • $\begingroup$ The confusion lies with Label Encoding, where an ordering is assumed between levels. Wouldn't this phenomenon be attributed with the gender variable ? $\endgroup$ – Gale Feb 23 '18 at 13:54
  • $\begingroup$ If there're only two levels, the ordering doesn't matter. Reordering the levels would just change the variable from is_female to is_male. You'd interpret the coefficient slightly differently and the intercept/bias would change as well to accommodate it, but that's really it. Try it out on some toy data and see what happens. $\endgroup$ – David Marx Feb 23 '18 at 22:37

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.