Accessing LightGBM model parameters

怎甘沉沦 提交于 2021-01-27 14:58:21

问题


Sometimes I save a LightGBM model and later, upon reloading it, want to access some details about how the model was built. Is there a way to recover the fact that objective = "regression", for example?

For convenience, here is brief code to play with:

library(lightgbm)
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
data(agaricus.test, package = "lightgbm")
params <- list(objective = "regression", metric = "l2")
model <- lgb.train(params,
                   dtrain,
                   100,
                   min_data = 1,
                   learning_rate = 1)
names(model)

I don't see how to retrieve any model parameters from any of the model attributes:

> names(model)
 [1] ".__enclos_env__"      "raw"                  "record_evals"         "best_score"          
 [5] "best_iter"            "save"                 "to_predictor"         "predict"             
 [9] "dump_model"           "save_model_to_string" "save_model"           "eval_valid"          
[13] "eval_train"           "eval"                 "current_iter"         "rollback_one_iter"   
[17] "update"               "reset_parameter"      "add_valid"            "set_train_data_name" 
[21] "initialize"           "finalize"   

回答1:


I'm not using the R binding of lightgbm, but looking through the Booster implementation in version 2.1.1, there seems to be indeed no interface to retrieve parameters. In turn, because params are not an attribute of the Booster class, but just passed down to the back-end C implementation.

Such functionality is also missing in the native python binding (the similar Booster class). However, it is present in the sklearn API. So the native API is consistently missing this function, but the higher-level wrapper in python has it added.



来源:https://stackoverflow.com/questions/49674112/accessing-lightgbm-model-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!