Unverified Commit f7c1a7f2 authored by Peyara Nando's avatar Peyara Nando Committed by GitHub
Browse files

[R-package] Updated lgb.Booster.R with keyword arguments (#3496)



* Updated lgb.Booster.R with keyword arguments

-I am facing problems while generating the docs
Little help please

* Update lgb.Booster.R

* Update lgb.Booster.R

* Clean up as requested

* Update lgb.Booster.R

* Update lgb.Booster.R

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update lgb.Booster.R

* Update lgb.Booster.R

* Revert "Update lgb.Booster.R"

This reverts commit 9b81ce845efa310ae6e5790f0e49b73c2ec5f250.

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update lgb.Booster.R

* Update lgb.Booster.R

* Update lgb.Booster.R

* Update lgb.Booster.R

* Update lgb.Booster.R

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Revert "Update lgb.Booster.R"

This reverts commit 4f2cc948f6e5ba53639ec646a500dcfd6b8a51ec.

* Update lgb.Booster.R

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update lgb.Booster.R

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update R-package/R/lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* Update lgb.Booster.R
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>
parent 88a7344c
...@@ -39,12 +39,12 @@ Booster <- R6::R6Class( ...@@ -39,12 +39,12 @@ Booster <- R6::R6Class(
# Check if training dataset is not null # Check if training dataset is not null
if (!is.null(train_set)) { if (!is.null(train_set)) {
# Check if training dataset is lgb.Dataset or not # Check if training dataset is lgb.Dataset or not
if (!lgb.check.r6.class(train_set, "lgb.Dataset")) { if (!lgb.check.r6.class(object = train_set, name = "lgb.Dataset")) {
stop("lgb.Booster: Can only use lgb.Dataset as training data") stop("lgb.Booster: Can only use lgb.Dataset as training data")
} }
train_set_handle <- train_set$.__enclos_env__$private$get_handle() train_set_handle <- train_set$.__enclos_env__$private$get_handle()
params <- modifyList(params, train_set$get_params()) params <- modifyList(params, train_set$get_params())
params_str <- lgb.params2str(params) params_str <- lgb.params2str(params = params)
# Store booster handle # Store booster handle
handle <- lgb.call( handle <- lgb.call(
"LGBM_BoosterCreate_R" "LGBM_BoosterCreate_R"
...@@ -84,7 +84,7 @@ Booster <- R6::R6Class( ...@@ -84,7 +84,7 @@ Booster <- R6::R6Class(
# Create booster from model # Create booster from model
handle <- lgb.call( handle <- lgb.call(
"LGBM_BoosterCreateFromModelfile_R" fun_name = "LGBM_BoosterCreateFromModelfile_R"
, ret = handle , ret = handle
, lgb.c_str(modelfile) , lgb.c_str(modelfile)
) )
...@@ -98,7 +98,7 @@ Booster <- R6::R6Class( ...@@ -98,7 +98,7 @@ Booster <- R6::R6Class(
# Create booster from model # Create booster from model
handle <- lgb.call( handle <- lgb.call(
"LGBM_BoosterLoadModelFromString_R" fun_name = "LGBM_BoosterLoadModelFromString_R"
, ret = handle , ret = handle
, lgb.c_str(model_str) , lgb.c_str(model_str)
) )
...@@ -116,7 +116,7 @@ Booster <- R6::R6Class( ...@@ -116,7 +116,7 @@ Booster <- R6::R6Class(
}) })
# Check whether the handle was created properly if it was not stopped earlier by a stop call # Check whether the handle was created properly if it was not stopped earlier by a stop call
if (lgb.is.null.handle(handle)) { if (isTRUE(lgb.is.null.handle(handle))) {
stop("lgb.Booster: cannot create Booster handle") stop("lgb.Booster: cannot create Booster handle")
...@@ -127,7 +127,7 @@ Booster <- R6::R6Class( ...@@ -127,7 +127,7 @@ Booster <- R6::R6Class(
private$handle <- handle private$handle <- handle
private$num_class <- 1L private$num_class <- 1L
private$num_class <- lgb.call( private$num_class <- lgb.call(
"LGBM_BoosterGetNumClasses_R" fun_name = "LGBM_BoosterGetNumClasses_R"
, ret = private$num_class , ret = private$num_class
, private$handle , private$handle
) )
...@@ -149,7 +149,7 @@ Booster <- R6::R6Class( ...@@ -149,7 +149,7 @@ Booster <- R6::R6Class(
add_valid = function(data, name) { add_valid = function(data, name) {
# Check if data is lgb.Dataset # Check if data is lgb.Dataset
if (!lgb.check.r6.class(data, "lgb.Dataset")) { if (!lgb.check.r6.class(object = data, name = "lgb.Dataset")) {
stop("lgb.Booster.add_valid: Can only use lgb.Dataset as validation data") stop("lgb.Booster.add_valid: Can only use lgb.Dataset as validation data")
} }
...@@ -189,7 +189,7 @@ Booster <- R6::R6Class( ...@@ -189,7 +189,7 @@ Booster <- R6::R6Class(
# Append parameters # Append parameters
params <- append(params, list(...)) params <- append(params, list(...))
params_str <- lgb.params2str(params) params_str <- lgb.params2str(params = params)
# Reset parameters # Reset parameters
lgb.call( lgb.call(
...@@ -216,7 +216,7 @@ Booster <- R6::R6Class( ...@@ -216,7 +216,7 @@ Booster <- R6::R6Class(
if (!is.null(train_set)) { if (!is.null(train_set)) {
# Check if training set is lgb.Dataset # Check if training set is lgb.Dataset
if (!lgb.check.r6.class(train_set, "lgb.Dataset")) { if (!lgb.check.r6.class(object = train_set, name = "lgb.Dataset")) {
stop("lgb.Booster.update: Only can use lgb.Dataset as training data") stop("lgb.Booster.update: Only can use lgb.Dataset as training data")
} }
...@@ -268,7 +268,7 @@ Booster <- R6::R6Class( ...@@ -268,7 +268,7 @@ Booster <- R6::R6Class(
# Return custom boosting gradient/hessian # Return custom boosting gradient/hessian
ret <- lgb.call( ret <- lgb.call(
"LGBM_BoosterUpdateOneIterCustom_R" fun_name = "LGBM_BoosterUpdateOneIterCustom_R"
, ret = NULL , ret = NULL
, private$handle , private$handle
, gpair$grad , gpair$grad
...@@ -311,7 +311,7 @@ Booster <- R6::R6Class( ...@@ -311,7 +311,7 @@ Booster <- R6::R6Class(
cur_iter <- 0L cur_iter <- 0L
lgb.call( lgb.call(
"LGBM_BoosterGetCurrentIteration_R" fun_name = "LGBM_BoosterGetCurrentIteration_R"
, ret = cur_iter , ret = cur_iter
, private$handle , private$handle
) )
...@@ -323,7 +323,7 @@ Booster <- R6::R6Class( ...@@ -323,7 +323,7 @@ Booster <- R6::R6Class(
upper_bound <- 0.0 upper_bound <- 0.0
lgb.call( lgb.call(
"LGBM_BoosterGetUpperBoundValue_R" fun_name = "LGBM_BoosterGetUpperBoundValue_R"
, ret = upper_bound , ret = upper_bound
, private$handle , private$handle
) )
...@@ -335,7 +335,7 @@ Booster <- R6::R6Class( ...@@ -335,7 +335,7 @@ Booster <- R6::R6Class(
lower_bound <- 0.0 lower_bound <- 0.0
lgb.call( lgb.call(
"LGBM_BoosterGetLowerBoundValue_R" fun_name = "LGBM_BoosterGetLowerBoundValue_R"
, ret = lower_bound , ret = lower_bound
, private$handle , private$handle
) )
...@@ -346,7 +346,7 @@ Booster <- R6::R6Class( ...@@ -346,7 +346,7 @@ Booster <- R6::R6Class(
eval = function(data, name, feval = NULL) { eval = function(data, name, feval = NULL) {
# Check if dataset is lgb.Dataset # Check if dataset is lgb.Dataset
if (!lgb.check.r6.class(data, "lgb.Dataset")) { if (!lgb.check.r6.class(object = data, name = "lgb.Dataset")) {
stop("lgb.Booster.eval: Can only use lgb.Dataset to eval") stop("lgb.Booster.eval: Can only use lgb.Dataset to eval")
} }
...@@ -387,7 +387,11 @@ Booster <- R6::R6Class( ...@@ -387,7 +387,11 @@ Booster <- R6::R6Class(
} }
# Evaluate data # Evaluate data
private$inner_eval(name, data_idx, feval) private$inner_eval(
data_name = name
, data_idx = data_idx
, feval = feval
)
}, },
...@@ -429,7 +433,7 @@ Booster <- R6::R6Class( ...@@ -429,7 +433,7 @@ Booster <- R6::R6Class(
# Save booster model # Save booster model
lgb.call( lgb.call(
"LGBM_BoosterSaveModel_R" fun_name = "LGBM_BoosterSaveModel_R"
, ret = NULL , ret = NULL
, private$handle , private$handle
, as.integer(num_iteration) , as.integer(num_iteration)
...@@ -450,7 +454,7 @@ Booster <- R6::R6Class( ...@@ -450,7 +454,7 @@ Booster <- R6::R6Class(
# Return model string # Return model string
return(lgb.call.return.str( return(lgb.call.return.str(
"LGBM_BoosterSaveModelToString_R" fun_name = "LGBM_BoosterSaveModelToString_R"
, private$handle , private$handle
, as.integer(num_iteration) , as.integer(num_iteration)
, as.integer(feature_importance_type) , as.integer(feature_importance_type)
...@@ -467,7 +471,7 @@ Booster <- R6::R6Class( ...@@ -467,7 +471,7 @@ Booster <- R6::R6Class(
} }
lgb.call.return.str( lgb.call.return.str(
"LGBM_BoosterDumpModel_R" fun_name = "LGBM_BoosterDumpModel_R"
, private$handle , private$handle
, as.integer(num_iteration) , as.integer(num_iteration)
, as.integer(feature_importance_type) , as.integer(feature_importance_type)
...@@ -496,7 +500,16 @@ Booster <- R6::R6Class( ...@@ -496,7 +500,16 @@ Booster <- R6::R6Class(
# Predict on new data # Predict on new data
predictor <- Predictor$new(private$handle, ...) predictor <- Predictor$new(private$handle, ...)
predictor$predict(data, start_iteration, num_iteration, rawscore, predleaf, predcontrib, header, reshape) predictor$predict(
data = data
, start_iteration = start_iteration
, num_iteration = num_iteration
, rawscore = rawscore
, predleaf = predleaf
, predcontrib = predcontrib
, header = header
, reshape = reshape
)
}, },
...@@ -554,7 +567,7 @@ Booster <- R6::R6Class( ...@@ -554,7 +567,7 @@ Booster <- R6::R6Class(
# Store predictions # Store predictions
npred <- 0L npred <- 0L
npred <- lgb.call( npred <- lgb.call(
"LGBM_BoosterGetNumPredict_R" fun_name = "LGBM_BoosterGetNumPredict_R"
, ret = npred , ret = npred
, private$handle , private$handle
, as.integer(idx - 1L) , as.integer(idx - 1L)
...@@ -587,7 +600,7 @@ Booster <- R6::R6Class( ...@@ -587,7 +600,7 @@ Booster <- R6::R6Class(
# Get evaluation names # Get evaluation names
names <- lgb.call.return.str( names <- lgb.call.return.str(
"LGBM_BoosterGetEvalNames_R" fun_name = "LGBM_BoosterGetEvalNames_R"
, private$handle , private$handle
) )
...@@ -631,7 +644,7 @@ Booster <- R6::R6Class( ...@@ -631,7 +644,7 @@ Booster <- R6::R6Class(
# Create evaluation values # Create evaluation values
tmp_vals <- numeric(length(private$eval_names)) tmp_vals <- numeric(length(private$eval_names))
tmp_vals <- lgb.call( tmp_vals <- lgb.call(
"LGBM_BoosterGetEval_R" fun_name = "LGBM_BoosterGetEval_R"
, ret = tmp_vals , ret = tmp_vals
, private$handle , private$handle
, as.integer(data_idx - 1L) , as.integer(data_idx - 1L)
...@@ -758,14 +771,14 @@ predict.lgb.Booster <- function(object, ...@@ -758,14 +771,14 @@ predict.lgb.Booster <- function(object,
# Return booster predictions # Return booster predictions
object$predict( object$predict(
data data = data
, start_iteration , start_iteration = start_iteration
, num_iteration , num_iteration = num_iteration
, rawscore , rawscore = rawscore
, predleaf , predleaf = predleaf
, predcontrib , predcontrib = predcontrib
, header , header = header
, reshape , reshape = reshape
, ... , ...
) )
} }
...@@ -873,7 +886,10 @@ lgb.save <- function(booster, filename, num_iteration = NULL) { ...@@ -873,7 +886,10 @@ lgb.save <- function(booster, filename, num_iteration = NULL) {
} }
# Store booster # Store booster
invisible(booster$save_model(filename, num_iteration)) invisible(booster$save_model(
filename = filename
, num_iteration = num_iteration
))
} }
...@@ -915,7 +931,7 @@ lgb.dump <- function(booster, num_iteration = NULL) { ...@@ -915,7 +931,7 @@ lgb.dump <- function(booster, num_iteration = NULL) {
} }
# Return booster at requested iteration # Return booster at requested iteration
booster$dump_model(num_iteration) booster$dump_model(num_iteration = num_iteration)
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment