在 R 中保存和加载模型 [英] Saving and loading a model in R

查看:75
本文介绍了在 R 中保存和加载模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 caret 时,如何保存训练后的模型,然后加载它(例如在不同的会话中)进行预测?

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

推荐答案

现在更好的解决方案是使用 saveRDS 保存和 readRDS 读取:

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)

这篇关于在 R 中保存和加载模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆