3

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 .RData files, but they don't solve the dependency or data dependency issue.

Edit: Tried the approach mentioned using save, load like below

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

But the loaded model model_diff contained string "Model1" instead of the contents of it.

Community
  • 1
  • 1
Prradep
  • 5,506
  • 5
  • 43
  • 84
  • So http://stackoverflow.com/questions/5118074/reusing-a-model-built-in-r is not sufficient? – Roman Luštrik Oct 01 '16 at 10:59
  • 1
    Even better, `saveRDS()` and `readRDS()` allow you to name the variable: `prradep_model <- readRDS("my_awesome_model.rds")` – m-dz Oct 01 '16 at 11:01
  • Roman, @m-dz thanks for the comments. I will look into these options and test them. – Prradep Oct 01 '16 at 11:18
  • @ari-b-friedman Thanks for the edit to make it as clear as possible. Could you please help me in understanding - " but they don't solve the dependency or data dependency issue" ?? – Prradep Oct 01 '16 at 12:29
  • 1
    Back compatibility can be a hassle in every software. If you really want to have a fully reproducible environment, you'll have to figure out how to encapsulate a specific R version and specific packages. See this discussion for more info: http://stackoverflow.com/questions/24283171/virtual-environment-in-r – Roman Luštrik Oct 01 '16 at 12:49
  • @RomanLuštrik The `save` function in the link mentioned in first comment did not work. – Prradep Oct 14 '16 at 11:22
  • Can you be more specific? What precisely did it not work? – Roman Luštrik Oct 16 '16 at 15:02
  • @RomanLuštrik I have used the `save` function and tried to load the object for using the model but it didn't load the model. – Prradep Oct 16 '16 at 15:42
  • What are the commands you use? Please add this information to the original question. – Roman Luštrik Oct 17 '16 at 09:28

1 Answers1

0

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.

Community
  • 1
  • 1
Prradep
  • 5,506
  • 5
  • 43
  • 84