Prradep Prradep - 1 year ago 70
R Question

How to share trained logistic models with others?

I have 5 logistic models trained using the private data. I want them to be validated on another private data by another member. How do I share share the trained models such that they can be evaluated on another system running an arbitrary version of R and packages (i.e. as portably as possible)? I know about

files, but they don't solve the dependency or data dependency issue.

Tried the approach mentioned using
like below

save(Model1, file = "my_model1.test.rda")
model_diff <- load('my_model1.test.rda')
[1] "Model1"

But the loaded model
contained string
instead of the contents of it.

Answer Source

If anyone looking for answer, models can be saved using saveRDS()

saveRDS(lm.model, 'my_model.rds')

and load them in different session using readRDS() function

Model_load <- readRDS('my_model.rds')

based on m-dz's answer.