How to save & load xgboost model?

后端 未结 5 451
南方客
南方客 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:17

    I found my way here because I was looking for a way to save and load my xgboost model. Here is how I solved my problem:

    import pickle
    file_name = "xgb_reg.pkl"
    
    # save
    pickle.dump(xgb_model, open(file_name, "wb"))
    
    # load
    xgb_model_loaded = pickle.load(open(file_name, "rb"))
    
    # test
    ind = 1
    test = X_val[ind]
    xgb_model_loaded.predict(test)[0] == xgb_model.predict(test)[0]
    
    Out[1]: True
    

提交回复
热议问题