Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-package] init_model should accept booster #5377

Closed
sebffischer opened this issue Jul 16, 2022 · 5 comments · Fixed by #5379
Closed

[R-package] init_model should accept booster #5377

sebffischer opened this issue Jul 16, 2022 · 5 comments · Fixed by #5379

Comments

@sebffischer
Copy link
Contributor

Summary

It would be great if one could pass the lgb.Booster directly as init_model and not have to save it to disk first.

@jameslamb jameslamb changed the title [feature request] init_model should accept booster (R) [R-package] init_model should accept booster Jul 16, 2022
@jameslamb
Copy link
Collaborator

Thanks for your interest in LightGBM!

It is possible to pass an lgb.Booster model into lgb.train() as init_model without saving it to disk.

The following minimal example works on the latest released version (v3.3.2) and on the latest development version (44fe591).

library(lightgbm)

data(agaricus.train, package = "lightgbm")

dtrain <- lgb.Dataset(
    agaricus.train$data
    , label = agaricus.train$label
    , free_raw_data = FALSE
)

initial_model <- lightgbm::lgb.train(
    data = dtrain
    , params = list(
        objective = "binary"
        , num_iterations = 10L
    )
)

new_model <- lightgbm::lgb.train(
    init_model = initial_model
    , data = dtrain
    , params = list(
        objective = "binary"
        , num_iterations = 17
    )
)
new_model$current_iter()
# 27

In the future, when you open issues here please provide the information asked for in the issue template. Including:

@sebffischer
Copy link
Contributor Author

Thanks, what threw me off here were the docs (version 3.2.2)

init_model: path of model file of ‘lgb.Booster’ object, will continue
          training from this model

@jameslamb
Copy link
Collaborator

ha! that should say "OR" lgb.Booster not "OF" .

Would you like to open a pull request fixing that in the documentation?

@sebffischer
Copy link
Contributor Author

Sure, will do it tomorrow :)

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues
including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants