# Analysis of categorical variables in BDT

**URL:** <https://root-forum.cern.ch/t/analysis-of-categorical-variables-in-bdt/27804>\
**Category:** TMVA\
**Created:** [February 4, 2018, 6:57am UTC](https://root-forum.cern.ch/t/analysis-of-categorical-variables-in-bdt/27804 "2018-02-04T06:57:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KarenDmn](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/a9a28c/32.png) [@KarenDmn](https://root-forum.cern.ch/u/KarenDmn)\
**Post date:** [February 4, 2018, 6:57am UTC](https://root-forum.cern.ch/t/analysis-of-categorical-variables-in-bdt/27804/1 "2018-02-04T06:57:33Z")

</div>

Hello friends of ROOT forum

I am using ROOT to analyze a survey of a group of people that to know them age, grades, profession, race, sex, origin country and if the annual income is less o more to 50,000 dollars. I divided this data into two half, the first half is training and second, testing, I have to be capable to determine the probability if a whoever person has an annual income less or more of 50,000 dollars in the second group of data.

It would be correct mathematical and computationally if I convert (for example)…  
Origin country: France -\>1, Mexico -\>2, …Australia-\>40, and with the transformed data use a BDT in ROOT?

By the way (excuse my English mistakes please)  
I am looking forward your answer

Atte: Karen

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [February 5, 2018, 5:11pm UTC](https://root-forum.cern.ch/t/analysis-of-categorical-variables-in-bdt/27804/2 "2018-02-05T17:11:30Z")

</div>

@moneta maybe you can help here?

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [February 7, 2018, 5:05pm UTC](https://root-forum.cern.ch/t/analysis-of-categorical-variables-in-bdt/27804/3 "2018-02-07T17:05:45Z")

</div>

Hi Karen,

This is possible to do but might lower the final accuracy of the predictor. This is because the linear coding introduces an artificial arithmetic relation. In your example `France * Mexico = Mexico`.

An alternative is to use a separate variable for each label and indicate its existence with a `1`. So if a person can come from France, Mexico, or someplace else the resulting vector could be e.g. `<1, 0>` for a French person and `<0, 1>` for a Mexican and `<0, 0>` for a person originating from Norway.

This is a bit tedious to implement in TMVA if there are many labels, so try the the coding you suggest first 🙂

Some more information can be found [here](https://en.wikipedia.org/wiki/Categorical_variable).

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![KarenDmn](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/a9a28c/32.png) [@KarenDmn](https://root-forum.cern.ch/u/KarenDmn)\
**Post date:** [March 5, 2018, 11:12pm UTC](https://root-forum.cern.ch/t/analysis-of-categorical-variables-in-bdt/27804/4 "2018-03-05T23:12:56Z")

</div>

I tried and it works fine, I checked statistical articles and books where they did the same as I do.  
Thanks for answering me 😃
