Saving and loading a model in R

前端 未结 3 704
粉色の甜心
粉色の甜心 2020-12-03 06:50

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

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 07:11

    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)

提交回复
热议问题