I want to force my decision tree to use specific variables, is it possible?

Viewed 20
tree = rpart(target~ main_var1+var1+var2+var3
             +var4+main_var2, 
                      data=df, 
                      method = 'anova',
                      control = c(maxdepth = 3, cp=0.00012, minsplit=80, xval=10))

I have this code to build a DecisionTree, however it builds it without using main_var1 and main_var2, is it possible to force it to use those variables?

1 Answers

You can write it as

ctree(target ~ ., df, controls = ctree_control(maxdepth = 3,  minsplit = 80, maxvar = 10))
Related