2
$\begingroup$

I'm very new to machine learning approaches. I'm reading a tutorial for build a predictive model using random forests. One of the transformations implemented was transform categorical variables to binary. Imagine (short sample):

Field_Desc  Field_Value
A               32
A               100
B               1

And then the developer pass this dataset into:

Field_A1    Field_B1    Field_Value
1               0                32
1               0                100
0               1                 1

What is the advantage to make this transformation for Random Forest Prediction? And for K-Means there will have any advantage?

Thanks!

$\endgroup$
0
$\begingroup$

Suppose that you want to have k-means algorithm, in the formulation of average, you have to take the average of each cluster, and then reassign the centers. If you have categorical data, how do you want to take mean? Changing categorical data to numeric data is for translating situations which don't have numerical features to be suited to be used for such algorithms.

$\endgroup$
0
$\begingroup$

Most random forest algorithms I have come across don't require that categorical variables are converted as you describe above, generally because of how the tree does its splitting:

  • Categorical variable with split point x: splitting rule is data point = x / data point != x.
  • Numeric variable with split point x: splitting rule is data point < x / data point >= x.

That being said, some algorithms have constraints on the cardinality of categorical variables - e.g. randomForest in R only accepts categorical variables with less than 53 levels.

$\endgroup$

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.