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: lgb.save does not retain full information of the booster object? #346

Closed
everdark opened this issue Mar 15, 2017 · 8 comments
Closed

Comments

@everdark
Copy link

everdark commented Mar 15, 2017

Hi,

I am just wondering whether this is what I should expect for the behaviour of lgb.save.
Here is my script to reproduce what I am confused:

require(lightgbm)
require(methods)

data(agaricus.train, package='lightgbm')
data(agaricus.test, package='lightgbm')
train <- agaricus.train
test <- agaricus.test

dtrain <- lgb.Dataset(data = train$data, label=train$label, free_raw_data=FALSE)
dtest <- lgb.Dataset(data = test$data, label=test$label, free_raw_data=FALSE)
valids <- list(train=dtrain, test=dtest)
bst <- lgb.train(data=dtrain, num_leaves=4, learning_rate=1, nrounds=2, valids=valids,
                 metric = c("binary_error","binary_logloss"),
                 nthread = 2, objective = "binary")

bst$record_evals # recorded here
lgb.save(bst, "some.model")
loaded <- lgb.load("some.model")
loaded$record_evals # it's gone

Since I'd like to also keep the eval metrics for each iteration. Can I achieve this by lgb.save. If it is not, I need to write out it on my own.

@Laurae2
Copy link
Contributor

Laurae2 commented Mar 15, 2017

@everdark use saveRDS and readRDS for R objects if you do not want to save only the model.

See issue #296.

@everdark
Copy link
Author

noted. thanks for the quick response.

@Laurae2
Copy link
Contributor

Laurae2 commented Mar 19, 2017

@everdark record_evals should now be stored if you use the serialization interface: #347

This will not work with lgb.save and lgb.load.

@everdark
Copy link
Author

Hi recently I just found that the model file output by R can not be used in CLI or python version due to lacking of the feature_infos. Does this mean that R is using a different version of lightgbm?

I already re-compiled lightgbm from master branch and re-install the python and R package.
I install the R package by using:

cd LightGBM/R-package
Rscript build_package.R
R CMD INSTALL lightgbm_0.2.tar.gz

Is this by design? or how can i output a model file from R that is also able to be used latter in python?

@everdark everdark reopened this Jun 19, 2017
@guolinke
Copy link
Collaborator

@everdark
I think cli, R and python share the same format of model file.
can you upload the model file generated by R here?

@everdark
Copy link
Author

everdark commented Jun 19, 2017

@guolinke
The file generated is like this:
https://transfer.sh/QFgkV/lgb.model

It is generated by a call to lgb.save after lgb.train.

Head of the file:
(there is no feature_infos as I could find for other model files generated by the cli/python examples)

tree
num_class=1
label_index=0
max_feature_idx=4
objective=binary
sigmoid=1
feature_names=yhat cate price len_title len_desc

Tree=0
num_leaves=20

@guolinke
Copy link
Collaborator

guolinke commented Jun 19, 2017

@Laurae2 can you help to this ?
I think maybe it is caused by the string format in R.
The line of "feature_info" contains something like [...].

@everdark
Copy link
Author

sorry I think the problem is solved.
Probably because I was loading R package from cache (which using the old ver of lightgbm).

@lock lock bot locked as resolved and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants