user2502904
user2502904

Reputation: 319

R save xgb model command error: 'model must be xgb.Booster'

'bst' is the name of an xgboost model that I built in R. It gives me predicted values for the test dataset using this code. So it is definitely an xgboost model.

pred.xgb <- predict(bst , xdtest)  # get prediction in test sample
cor(ytestdata, pred.xgb)

Now, I would like to save the model so another can use the model with their data set which has the same predictor variables and the same variable to be predicted.

Consistent with page 4 of xgboost.pdf, the documentation for the xgboost package, I use the xgb.save command:

xgb.save(bst, 'xgb.model') 

which produces the error:

Error in xgb.save(bst, "xgb.model") : model must be xgb.Booster.

Any insight would be appreciated. I searched the stack overflow and could not locate relevant advice.

Mike

Upvotes: 0

Views: 485

Answers (1)

Ekholme
Ekholme

Reputation: 393

It's hard to know exactly what's going on without a fully reproducible example. But just because your model can make predictions on the test data, it doesn't mean it's an xgboost model. It can be any type of model with a predict method.

You can try class(bst) to see the class of your bst object. It should return "xgb.Booster," though I suspect it won't here (hence your error).

On another note, if you want to pass your model to another person using R, you can just save the R object rather than exporting to binary, via:

save(bst, model.RData)

Upvotes: 1

Related Questions