# How to convert binary category feature to numeric feature, like 'Gender'?

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'

thx

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).
• 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. – nikie Feb 20 '17 at 16:00