-1

I am trying to figure how to get the linear model at each leaf of a tree generated by M5P method in RWeka library in R as an output to text file so that I can write a separate look up calculator program (say in Excel for non-R Users).

I am using

library (RWeka)
model = M5P (response ~ predictorA+predictorB, data=train).

I can get the tree output as model$classifier in a matrix. This works great thanks to This post

If I give the command:

model

R prints the model$classifier (the tree structure), followed by the LM at each leaf, I want to extract the coefficients of LM at each leaf.

M--
  • 25,431
  • 8
  • 61
  • 93
user2162611
  • 146
  • 3
  • 13
  • Using the following code: I am able to get the LM coefficients out of R. Sorry to bother. `code` library(rJava) `code`ModelTree=as.matrix(scan(text=.jcall(model$classifier, "S","toString") ,sep="\n", what="") )[-c(1:2, 6), ,drop=FALSE] – user2162611 May 23 '17 at 19:29

1 Answers1

0

Using the following code: I am able to get the LM coefficients out of R.

library(rJava)      
ModelTree=as.matrix(scan(text=.jcall(model$classifier, "S","toString") ,sep="\n", what="") )[-c(1:2, 6), ,drop=FALSE]
M--
  • 25,431
  • 8
  • 61
  • 93
user2162611
  • 146
  • 3
  • 13