Saving and loading a model in R

前端 未结 3 680
粉色の甜心
粉色の甜心 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:31

    The following code assumes that your model's variable name is 'model':

    save(model, "model.RData")
    

    This will save your model as "model.RData" in the current working directory. You can find out what the working directory is by issuing the following:

    getwd()
    

    To load it back in, ensure that your model is saved in your working directory and issue:

    load("model.RData")
    

提交回复
热议问题