1
$\begingroup$

All I can find online is how a random forest is run on all variables in a dataset using the period:

RF <- randomForest(sale ~ ., data = TrainSet, importance = TRUE)

What if I only want to apply the RF to selected variables in the dataset? Would I need to drop the variables first?

I tried the following, but get an error: RF <- randomForest(sale ~ v1,v2,v3, data = TrainSet, importance = TRUE)

$\endgroup$
1
  • $\begingroup$ Please add the error message. $\endgroup$
    – C8H10N4O2
    Commented Jun 19, 2020 at 14:09

1 Answer 1

1
$\begingroup$

You have to do

RF <- randomForest(sale ~ v1 + v2 + v3, data = TrainSet, importance = TRUE)

this is the formula notation for R. It doesn't make a lot of sense for random forest models, but it is how it works.

$\endgroup$

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.