Skip to content

Commit 7389222

Browse files
committed
more robust xgboost param moving
1 parent 498fab0 commit 7389222

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

R/boost_tree.R

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,15 @@ xgb_train <- function(
345345
arg_list$num_class <- num_class
346346
}
347347

348-
if (!is.null(others$objective)) {
349-
arg_list$objective <- others$objective
350-
others$objective <- NULL
351-
}
352-
if (!is.null(others$eval_metric)) {
353-
arg_list$eval_metric <- others$eval_metric
354-
others$eval_metric <- NULL
355-
}
356-
if (!is.null(others$nthread)) {
357-
arg_list$nthread <- others$nthread
358-
others$nthread <- NULL
348+
param_names <- names(formals(xgboost::xgb.params))
349+
350+
if (any(param_names %in% names(others))) {
351+
elements <- param_names[param_names %in% names(others)]
352+
353+
for (element in elements) {
354+
arg_list[[element]] <- others[[element]]
355+
others[[element]] <- NULL
356+
}
359357
}
360358

361359
if (is.null(arg_list$objective)) {

0 commit comments

Comments
 (0)