可以使用lightgbm.train 的init_model选项解决,它接受两个对象之一
- LightGBM 模型的文件名,或
- 一个 lightgbm Booster 对象
代码说明:
import numpy as np
import lightgbm as lgb
data = np.random.rand(1000, 10) # 1000 entities, each contains 10 features
label = np.random.randint(2, size=1000) # binary target
train_data = lgb.Dataset(data, label=label, free_raw_data=False)
params = {}
#Initialize with 10 iterations
gbm_init = lgb.train(params, train_data, num_boost_round = 10)
print("Initial iter# %d" %gbm_init.current_iteration())
# Example of option #1 (pass a file):
gbm_init.save_model('model.txt')
gbm = lgb.train(params, train_data, num_boost_round = 10,
init_model='model.txt')
print("Option 1 current iter# %d" %gbm.current_iteration())
# Example of option #2 (pass a lightgbm Booster object):
gbm_2 = lgb.train(params, train_data, num_boost_round = 10,
init_model = gbm_init)
print("Option 2 current iter# %d" %gbm_2.current_iteration())
https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.train.html