I have a R code, which has a trained machine learning model. Now I want to get prediction for new data.
Current method:
Script code.R '[{"x1" : "1011", "x2" : "1031", "x4" : "0.65"}]'
I would get the answer back, the problem was it took too much time just to load and set up the environment
Code:
# Loading the library
suppressPackageStartupMessages(library(C50))
suppressPackageStartupMessages(library(jsonlite))
suppressPackageStartupMessages(library(plyr))
# Loading the trained model
model1 <- readRDS("model1.RDA")
x <- (args[1])
# Function which wraps prediction and son handling
output <- function(x) {
df <- fromJSON(x)
df[is.na(df)] <- 0
prediction <- predict.C5.0(model1, newdata = df, type = "class")
json_df <- toJSON(prediction)
return(json_df)
}
output(x)
Problem:
I would like to use Rserve and pass parameters to this, I am not able to figure it out how? What modification should I do?
I know to add library(Rserve) and then do run.Rserve() but beyond that I don't know how?