方法一(适用于sklearn接口:from lightgbm import LGBMClassifier)
比如现在有一个lgbm_model
import joblib
# 保存
joblib.dump(lgbm_model, "lgbm_model.pkl")
# 加载
my_model = joblib.load("lgbm_model.pkl")
方法二(适用于原生接口:import lightgbm):
这里容易报错:TypeError: Need at least one training dataset or model file or model string to create Booster instance
# 保存
lgbm_model.save_model('model.txt')
# 加载
my_model = lightgbm.Booster(model_file='model.txt') # 注意这里指定model_file