0

I have built a M5 model tree using the train function of the caret package. I am trying to extract the linear model coefficients for each model of the tree.

The final model is called m5tune. I tried to look into m5tune$finalModel but I did not find it. The coeff() function does not seem to work either...

jmuhlenkamp
  • 2,030
  • 1
  • 13
  • 35
lbo34
  • 21
  • 1
  • Dear [Ibo34](https://stackoverflow.com/users/9851830/lbo34), welcome to SO. Please take a look at [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), to modify your question, with a smaller sample taken from your data (check?dput()). Posting images of your data or no data makes it difficult to impossible for us to help you! – massisenergy Dec 18 '18 at 15:17
  • I had a look in `finalModel` and could not find the regression coefficients readily available. The object that seems to hold them is `finalModel$classifier` but this is only a handle (`jobref`) for a java object... – asachet Dec 18 '18 at 15:44
  • What I am trying to do is to plot the linear model coefficients for each node of the tree. finalModel displays the coefficients on the screen, but I did not find a way to extract them in a data table for instance to plot them. – lbo34 Dec 19 '18 at 19:02

1 Answers1

0

Using this approach, you can get the correlation coefficient. Please the data is only representative.

library(Rweka)
iris1<-as.data.frame(iris)
set.seed(456)
mytrain<-createDataPartition(iris$Sepal.Length,p=0.8,list=F)
trainme<-iris[mytrain,]
mymodel<-train(Sepal.Length~.,trainme,trControl=trainControl(method="cv",number=5),method="M5",
               metric="MAE")

Simply calling this gives you the correlation coefficient.

summary(mymodel)
NelsonGon
  • 12,469
  • 5
  • 25
  • 52
  • Yes, but what I want is not the correlation coefficient. I want the coefficients of the linear equations for each node, so I can plot them side by side... – lbo34 Dec 20 '18 at 20:51