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 ?
1 Answer
$\begingroup$
$\endgroup$
3
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".
-
$\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$– GaleCommented Feb 23, 2018 at 13:54
-
2$\begingroup$ If there're only two levels, the ordering doesn't matter. Reordering the levels would just change the variable from
is_female
tois_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$ Commented Feb 23, 2018 at 22:37 -
$\begingroup$ When does it become an issue? Also, doesn't that mean you could represent four categories as two binary columns? $\endgroup$– ConnorCommented Apr 4, 2023 at 14:10