# Changing attributes from nominal to binary

Reading this book, I found the following description regarding model trees for numeric prediction, in which nominal attributes are transformed to binary attributes.

Before constructing a model tree, all nominal attributes are transformed into binary variables that are then treated as numeric. For each nominal attribute, the average class value corresponding to each possible value in the set is calculated from the training instances, and the values are sorted according to these averages. Then, if the nominal attribute has k possible values, it is replaced by k – 1 synthetic binary attributes, the ith being 0 if the value is one of the first i in the ordering and 1 other­ wise. Thus, all splits are binary: They involve either a numeric attribute or a synthetic binary attribute that is treated as numeric.

Well, I don't understand what it means. For example, suppose I have a Fruits attribute with several values such as Apple, Orange, Pear with some numeric class C1 for each instance. I think that by average class value that paragraph refers to the average in C1 for Apple, Orange, Pear.

But then what is doing to convert those nominal attributes to binary and why does it take k possible values (in this case, k should be 3) and returns k-1 binary attributes?

By the way, it seems that the class NominalToBinary here does exactly that but I don't have weka installed nor I know how to use it. I also took the example using Fruits as attribute from here.

I would appreciate an explanation or an example.

Thanks a lot.

Here's how the binary values for Apple, Orange and Pear are calculated. You know it has two binary digits (since k=3 and it has k-1 digits), so you compute each of those two digits:

• Apple is one of the first 1 in the ordering, so its first digit is 1. Apple is one of the first 2 in the ordering, so its second digit is 1.

• Orange is not one of the first 1 in the ordering, so its first digit is 0. Orange is one of the first 2 in the ordering, so its second digit is 1.

• Pear is not one of the first 1 in the ordering, so its first digit is 0. Pear is not one of the first 2 in the ordering, so its second digit is 0.

Thus, they are translated into: 11, 01, 00.

If you had 10 attributes, they would become:

111111111, 011111111, 001111111, 000111111, 000011111, 000001111,
000000111, 000000011, 000000001, 000000000

• Excellent answer. This is assuming that the ordering of Apple, Orange, and Pear is given according to the average of C1 (the class of the instance) in the instances that share the same value. Is that right? Jan 19, 2013 at 21:37
• @RobertSmith: That's right. Jan 19, 2013 at 21:39
• Great. Last question: What kind of split is performed with those binary attributes? Jan 19, 2013 at 21:45
• @RobertSmith: According to your quote, they are split the same way that numeric attributes are split. That is, they're converted into decimal: 11, 01, 00 are treated the same way you'd treat 3, 1, 0. 10 variables would become 511, 255, 127, 63, 31, 15, 7, 3, 1, 0. Jan 19, 2013 at 21:49