user1859050 user1859050 - 1 month ago 26
Java Question

How to save a C5.0 model in R and load in another environment

I have created a model using C50 library in R for classifying emails into various categories. I now want to use the model for classifying new incoming emails in real time using R predict via java. I am not sure how I can save the model from R and load it in another R instance that is used with Java.
Is there any way to save the model to a file and then load the file into R to get the model back for prediction?

Answer

This post has your answer to how to save a model (which is a java object) into a file, and then later load that file back again:

Save/load a M5 RWeka caret model fails

library(RWeka) 
j48.model <- J48(formula=class ~ ., data=data) 
library(rJava) 
.jcache(j48.model$classifier) 
save(j48.model, file="j48.model.rda")