1

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?

mitrabhanu
  • 389
  • 1
  • 2
  • 13

2 Answers2

1

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")
Community
  • 1
  • 1
MachLearn
  • 26
  • 1
0

I used below to save the model from randomForest as I migrated to Radom Forests from Trees. :) . I have also used combine so as to have multiple Random Forests added in same model.

mod <- randomForest(as.factor(type)~.-type,data1_rf[,c(5:52)],proximity=FALSE,mtry=5,nodesize=10,ntree=500,importance=FALSE)
mod1 <- randomForest(as.factor(type)~.-type,data2_rf[,c(5:52)],proximity=FALSE,mtry=5,nodesize=10,ntree=500,importance=FALSE)
mod <- combine(mod,mod1)

Then just save the final model into a file.

save(mod,file="/Rscripts/Models/MULTI23Jul2016.RData")

For using it, load the model.

mod<-get(load("/Rscripts/Models/MULTI23Jul2016.RData"))
mitrabhanu
  • 389
  • 1
  • 2
  • 13