In a machine learning or data mining problem, suppose I have a original feature named "Gender", and now I want to convert this feature to numeric feature, there are two ways to do that, but I realy do not know which one is better?

  1. Convert to one feature, and 1 represented 'male' and 0 represented 'female'
  2. Convert to two diffent feature, just like one-hot encoding, like 'ismale' and other one is 'isfemale'



The second coding brings absolutely no information, since ismale is perfectly correlated to isfemale and always if first is true, then the second must be false. So introducing the second variable does nothing. In general, to encode $k$ categories, you need $k-1$ dummy variables, since if each of the $k-1$ dummies it false, then $k$'th "default" category must be true (assuming that your data represents something like single-choice questions, so the categories are exclusive and exactly one needs to be true).

See also related threads
Why is gender typically coded 0/1 rather than 1/2, for example?
Why 0 for failure and 1 for success in a Bernoulli distribution?

You may also be interested in reading the What is a contrast matrix (a term, pertaining to an analysis with categorical predictors)? thread.

  • $\begingroup$ This might depend on the classifier, though, at least for for $k$ categories. For example, if you used feature selection, and the $k$th feature is needed, your feature selection algorithm would have to keep all $k-1$ features. $\endgroup$ – nikie Feb 20 '17 at 16:00

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.