Skip to content

Commit 6fecfb8

Browse files
committed
add drop = FALSE to matrix subsetting in as_xgb_data()
1 parent acad61e commit 6fecfb8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

R/boost_tree.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,22 @@ as_xgb_data <- function(x, y, validation = 0, weights = NULL, event_level = "fir
435435
# Split data
436436
m <- floor(n * (1 - validation)) + 1
437437
trn_index <- sample(seq_len(n), size = max(m, 2))
438-
val_data <- xgboost::xgb.DMatrix(x[-trn_index,], label = y[-trn_index], missing = NA)
438+
val_data <- xgboost::xgb.DMatrix(
439+
data = x[-trn_index, , drop = FALSE],
440+
label = y[-trn_index],
441+
missing = NA
442+
)
439443
watch_list <- list(validation = val_data)
440444

441445
info_list <- list(label = y[trn_index])
442446
if (!is.null(weights)) {
443447
info_list$weight <- weights[trn_index]
444448
}
445-
dat <- xgboost::xgb.DMatrix(x[trn_index,], missing = NA, info = info_list)
446-
449+
dat <- xgboost::xgb.DMatrix(
450+
data = x[trn_index, , drop = FALSE],
451+
missing = NA,
452+
info = info_list
453+
)
447454

448455
} else {
449456
info_list <- list(label = y)

0 commit comments

Comments
 (0)