4
votes

After training an XGBoost model in R, I am presented with a model object called xgb which is a list of 7.

When I save the model using xgb.save and then reload using xgb.load, I am presented with what seems to be a 'smaller' model object which is a list of 2.

Obviously I can't share the code as you would need the training data which is massive, so all I can really show is a picture of the variable editor.

Below is model object xgb which is the original model after training, vs. the model object test1 which is the same model but saved and reloaded:

enter image description here

Why does this happen and am I losing valuable information upon saving/loading my models?

Any help is appreciated.

2

2 Answers

1
votes

Maybe late, but I was having the same problem and found a solution.

Saving the xgb-model as "rds" doesn't loose any information and the reloaded model xgb_ does generate the same forecast values as the original xgb when I tested it. Hope that helps!

saveRDS(xgb, "model.rds")
xgb_ <- readRDS("model.rds")
all.equal(xgb, xgb_)
0
votes

You are loosing information due to rounding errors after save/load. See this issue. I believe it is currently a bug.

As to why the loaded model is a smaller list, see here. So again, you are loosing information such as the callbacks and parameters. But these are not essential for prediction and not portable to e.g. python.