Prediction using saved model object

一曲冷凌霜 提交于 2019-12-05 21:46:47

As @droopy told you the model's name doesn't change if you save and load. You can use get to use the model:

predicted <- predict(get(bar),validationData,type = "response")

If you have saved the model earlier it may throw this error. Reload the library(glmnet) and make sure that number of variables in X & Y are same.

I have same problem before.

I used caret to build model, and save the model as a rds file.(saveRDS)

When I readRDS my file, and use this model to predict, I encountered this problem.

After I use "library(caret)", my problem is solved.

So I think if you save your model, and re-open your model to predict, you have to reload the package you used for building model.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!