How to save & load xgboost model?

后端 未结 5 459
南方客
南方客 2020-12-04 18:00

On the link of XGBoost guide:

After training, the model can be saved.

bst.save_model(\'0001.model\')

The model a

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 18:25

    If you are using the sklearn api you can use the following:

    
    xgb_model_latest = xgboost.XGBClassifier() # or which ever sklearn booster you're are using
    
    xgb_model_latest.load_model("model.json") # or model.bin if you are using binary format and not the json
    

    If you used the above booster method for loading, you will get the xgboost booster within the python api not the sklearn booster in the sklearn api.

    So yeah, this seems to be the most pythonic way to load in a saved xgboost model data if you are using the sklearn api.

提交回复
热议问题