0
train_control <- trainControl(method='cv', number=10)    
model <- train(Class ~ Age+BMI+DBP+DPF+NumPregnancies+PG2+SI2+TSFT, method ='rf',data=input,trControl=train_control)

pmml(model$finalModel)
#Error in names(field$class) <- var.names : attempt to set an attribute on NULL

When I try to export the caret trained RF model to PMML, It fails. Is there a method to run RF manually using the optimal parameters tuned by caret package so that I can export the model to PMML?

Yehoshaphat Schellekens
  • 2,305
  • 2
  • 22
  • 49
madawa
  • 496
  • 6
  • 24
  • What's the error you get exactly? Your example isn't reproducible because `tr_con` isn't defined. – MrFlick Jan 27 '15 at 05:36
  • Can you please provide a reproducible example? It's not clear what library you're using even. – emhart Jan 27 '15 at 05:47
  • http://stackoverflow.com/questions/27428748/caret-model-random-forest-into-pmml-error In an answer given to this question, it says that caret rf model cannot be exported as pmml and recommends to use the following two-level approach. First, use the Caret package to find the most appropriate RF parameters for the data set. Second, train the final RF model manually using the "formula interface" with this parameters. I want to know how the **second part** of this can be done. – madawa Jan 27 '15 at 15:31
  • @DistribEcology I'm using the **caret** library in R – madawa Jan 27 '15 at 15:36
  • Did you load the `randomForest` package before running the `pmml` command? – topepo Jan 27 '15 at 20:08

2 Answers2

1

Tuned Parameters can be accessed through model$bestTune

> model$bestTune
mtry
3   23
madawa
  • 496
  • 6
  • 24
0

The "rf" method in caret make use of the randomForest package and randomForest function. This is if you want to run basic random forest "manually", without caret.

BBrill
  • 1,922
  • 17
  • 17