Currently I have a data-set with roughly 7 types of nominal data; these are things like "workclass" or "marital status". It is my understanding it is best to convert nominal data like this into numeric data. So, what I've done so far, as a simple experiment, is make up a dictionary for each nominal data type, so in our example of "marital status", it would be "Divorced":0, "Married":1, "Widowed":3, "Separated":4.

However, as I understand, there are some problems with this approach, as it implies that Divorced->Married are more related than Divorced->Widowed. I tried to arrange this data into a logical pattern, but for a lot of it its impossible. So here are my questions:

  1. Is there a good approach to do this without running into the above problem, specifically in Python? I'm using Pandas DF's at the moment, and I saw an example online of something called Binary Vectorizers, but I'm not sure if that won't introduce too many attributes/columns to my data set.
  2. When I convert a nominal value to an interval one, do I replace the original (For example Workclass) with the Workclass_Number data? Do I only enter the number data into my models?
  3. Are there any guidelines on the numbers that should be used? For example I used simple intervals of 1 for all of my data, starting at 0.

1 Answer 1

  1. Usually, when dealing with nominal attributes, you want to use the binary vectoriser approach. Unless you have a very large number of nominal values, it typically doesn't matter that you're adding a few attributes. If you do have a huge amount of nominal values, you can try things like dimensionality reduction on the binary attributes (although this reduces interpretability) or joining some nominal values together.

  2. Yes.

  3. If the nominal attribute is discrete but ordered (called an ordinal attribute) -- for example, the severity of a cancer (stage 1, 2, 3 or 4) -- then you can use whatever numbers you feel are appropriate. It really depends on your domain knowledge, and the choice of model. For some models like decision trees, it doesn't matter, but for others like logistic regression the choices of the numbers can be influential. I would recommend just continuing as you have been by using intervals of 1, unless your knowledge of the domain says that particular adjacent nominal values should be further or closer than the others.


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.