user1804773
user1804773

Reputation: 31

Random Forest in R - many classes

I want to do a multilabel classification with R randomForest. I have ten classes A..J,

I found examples how to predict a single class, like:

r = randomForest(J ~., data=train, importance=TRUE, do.trace=100)

But I want to predict more classes, for instance H,I,J. (i.e. say that only A..G are given attributes). How can I do it?

I have an idea of preserving A..G and only one of the predicted classes (H/I/J) and run randomForest 3 times, but maybe there is a better way? To do it in one run?

Many thanks in advance.

Upvotes: 3

Views: 1909

Answers (1)

user824276
user824276

Reputation: 637

Let's say that all attributes H, I and J are binary. Then you can just predict a new attribute K with 2^3 possible values and then decode the result back into 3 attributes:

  • 1 -> 0,0,0
  • 2 -> 0,0,1
  • 3 -> 0,1,0
  • 4 -> 0,1,1
  • 5 -> 1,0,0
  • 6 -> 1,0,1
  • 7 -> 1,1,0
  • 8 -> 1,1,1

Upvotes: 2

Related Questions