I am training a model using cross validation like so:
classifier = lgb.Booster(
params=params,
train_set=lgb_train_set,
)
result = lgb.cv(
init_model=classifier,
params=params,
train_set=lgb_train_set,
num_boost_round=1000,
early_stopping_rounds=20,
verbose_eval=50,
shuffle=True
)
I would like to continue training the model be running the second command multiple times (maybe with a new training set or with different parameters) and it would continue improving the model.
However, when I try this it is clear that the model is starting from scratch each time.
Is there a different approach to do what I am intending?
Can be solved using init_model option of lightgbm.train, which accepts one of two objects
Code illustration:
https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.train.html
to carry on training you must do
lgb.train
again and ensure you include in the parametersinit_model='model.txt'
. To confirm you have done correctly the information feedback during training should continue fromlgb.cv
. Then save the models best iteration like thisbst.save_model('model.txt', num_iteration=bst.best_iteration)
.It seems that lightgbm does not allow to pass model instance as init_model, because it takes only filename:
link