Saving and loading a model in R

Amelio Vazquez-Reina picture Amelio Vazquez-Reina · Feb 7, 2013 · Viewed 25.6k times · Source

When working with caret, how can I save a model after training, and load it later (e.g. in a different session) for prediction?

Answer

lbcommer picture lbcommer · Feb 17, 2017

A better solution nowadays is to use saveRDS to save and readRDS to read:

saveRDS(model, "model.rds")
my_model <- readRDS("model.rds")

This lets you to choose a new name for the object (you don't need to remember the name you used when you saved it)