xgboost how to copy model

Viewed 1034

In the xgboost documentation they refer to a copy() method, but I can't figure out how to use it since if foo is my model, neither bar = foo.copy() nor bar=xgb.copy(foo) works (xgboost can't find a copy() attribute of either the module or the model). Any suggestions?

2 Answers

It turns out that copy() is a method of the Booster object, but a (say) XGBClassifier is not one, so if using the sklearn front end, you do bar = foo.get_booster().copy()

sklearn.base.clone() will make a deep copy of a model without copying attached data. It may be what you are looking for. Just remember, it's a function, not a method, so don't make the mistake I did of sticking .clone after my identifier :-)

Usage :

## assume e as an estimator is defined and sklearn is already imported.
e = sklearn.base.clone(estimator)
e is estimator ## should return False

HTH

Related