Save LGBMRegressor model from python lightgbm package to disc

Utpal Datta picture Utpal Datta · Mar 17, 2019 · Viewed 16.5k times · Source

Hi I am unable to find an way to save and reuse an LGBM model to a file. I used python package lightgbm and LGBMRegressor model. Could you please help? Documentations doesn't seem to have useful information. I am using python 3.5 on Spyder

Answer

Prayson W. Daniel picture Prayson W. Daniel · Mar 17, 2019

Try:

my_model.booster_.save_model('mode.txt')
#load from model:

bst = lgb.Booster(model_file='mode.txt')

You can also use pickle:

import joblib
# save model
joblib.dump(my_model, 'lgb.pkl')
# load model
gbm_pickle = joblib.load('lgb.pkl')

Let me know if that helps