[R] Rename watchlist -> evals (#10032)
This commit is contained in:
@@ -20,7 +20,7 @@ test_that("train and predict binary classification", {
|
||||
data = xgb.DMatrix(train$data, label = train$label), max_depth = 2,
|
||||
eta = 1, nthread = n_threads, nrounds = nrounds,
|
||||
objective = "binary:logistic", eval_metric = "error",
|
||||
watchlist = list(train = xgb.DMatrix(train$data, label = train$label))
|
||||
evals = list(train = xgb.DMatrix(train$data, label = train$label))
|
||||
),
|
||||
"train-error"
|
||||
)
|
||||
@@ -152,7 +152,7 @@ test_that("train and predict softprob", {
|
||||
data = xgb.DMatrix(as.matrix(iris[, -5]), label = lb),
|
||||
max_depth = 3, eta = 0.5, nthread = n_threads, nrounds = 5,
|
||||
objective = "multi:softprob", num_class = 3, eval_metric = "merror",
|
||||
watchlist = list(train = xgb.DMatrix(as.matrix(iris[, -5]), label = lb))
|
||||
evals = list(train = xgb.DMatrix(as.matrix(iris[, -5]), label = lb))
|
||||
),
|
||||
"train-merror"
|
||||
)
|
||||
@@ -203,7 +203,7 @@ test_that("train and predict softmax", {
|
||||
data = xgb.DMatrix(as.matrix(iris[, -5]), label = lb),
|
||||
max_depth = 3, eta = 0.5, nthread = n_threads, nrounds = 5,
|
||||
objective = "multi:softmax", num_class = 3, eval_metric = "merror",
|
||||
watchlist = list(train = xgb.DMatrix(as.matrix(iris[, -5]), label = lb))
|
||||
evals = list(train = xgb.DMatrix(as.matrix(iris[, -5]), label = lb))
|
||||
),
|
||||
"train-merror"
|
||||
)
|
||||
@@ -226,7 +226,7 @@ test_that("train and predict RF", {
|
||||
nthread = n_threads,
|
||||
nrounds = 1, objective = "binary:logistic", eval_metric = "error",
|
||||
num_parallel_tree = 20, subsample = 0.6, colsample_bytree = 0.1,
|
||||
watchlist = list(train = xgb.DMatrix(train$data, label = lb))
|
||||
evals = list(train = xgb.DMatrix(train$data, label = lb))
|
||||
)
|
||||
expect_equal(xgb.get.num.boosted.rounds(bst), 1)
|
||||
|
||||
@@ -250,7 +250,7 @@ test_that("train and predict RF with softprob", {
|
||||
objective = "multi:softprob", eval_metric = "merror",
|
||||
num_class = 3, verbose = 0,
|
||||
num_parallel_tree = 4, subsample = 0.5, colsample_bytree = 0.5,
|
||||
watchlist = list(train = xgb.DMatrix(as.matrix(iris[, -5]), label = lb))
|
||||
evals = list(train = xgb.DMatrix(as.matrix(iris[, -5]), label = lb))
|
||||
)
|
||||
expect_equal(xgb.get.num.boosted.rounds(bst), 15)
|
||||
# predict for all iterations:
|
||||
@@ -271,7 +271,7 @@ test_that("use of multiple eval metrics works", {
|
||||
data = xgb.DMatrix(train$data, label = train$label), max_depth = 2,
|
||||
eta = 1, nthread = n_threads, nrounds = 2, objective = "binary:logistic",
|
||||
eval_metric = "error", eval_metric = "auc", eval_metric = "logloss",
|
||||
watchlist = list(train = xgb.DMatrix(train$data, label = train$label))
|
||||
evals = list(train = xgb.DMatrix(train$data, label = train$label))
|
||||
),
|
||||
"train-error.*train-auc.*train-logloss"
|
||||
)
|
||||
@@ -283,7 +283,7 @@ test_that("use of multiple eval metrics works", {
|
||||
data = xgb.DMatrix(train$data, label = train$label), max_depth = 2,
|
||||
eta = 1, nthread = n_threads, nrounds = 2, objective = "binary:logistic",
|
||||
eval_metric = list("error", "auc", "logloss"),
|
||||
watchlist = list(train = xgb.DMatrix(train$data, label = train$label))
|
||||
evals = list(train = xgb.DMatrix(train$data, label = train$label))
|
||||
),
|
||||
"train-error.*train-auc.*train-logloss"
|
||||
)
|
||||
@@ -295,19 +295,19 @@ test_that("use of multiple eval metrics works", {
|
||||
|
||||
test_that("training continuation works", {
|
||||
dtrain <- xgb.DMatrix(train$data, label = train$label, nthread = n_threads)
|
||||
watchlist <- list(train = dtrain)
|
||||
evals <- list(train = dtrain)
|
||||
param <- list(
|
||||
objective = "binary:logistic", max_depth = 2, eta = 1, nthread = n_threads
|
||||
)
|
||||
|
||||
# for the reference, use 4 iterations at once:
|
||||
set.seed(11)
|
||||
bst <- xgb.train(param, dtrain, nrounds = 4, watchlist, verbose = 0)
|
||||
bst <- xgb.train(param, dtrain, nrounds = 4, evals = evals, verbose = 0)
|
||||
# first two iterations:
|
||||
set.seed(11)
|
||||
bst1 <- xgb.train(param, dtrain, nrounds = 2, watchlist, verbose = 0)
|
||||
bst1 <- xgb.train(param, dtrain, nrounds = 2, evals = evals, verbose = 0)
|
||||
# continue for two more:
|
||||
bst2 <- xgb.train(param, dtrain, nrounds = 2, watchlist, verbose = 0, xgb_model = bst1)
|
||||
bst2 <- xgb.train(param, dtrain, nrounds = 2, evals = evals, verbose = 0, xgb_model = bst1)
|
||||
if (!windows_flag && !solaris_flag) {
|
||||
expect_equal(xgb.save.raw(bst), xgb.save.raw(bst2))
|
||||
}
|
||||
@@ -315,7 +315,7 @@ test_that("training continuation works", {
|
||||
expect_equal(dim(attributes(bst2)$evaluation_log), c(4, 2))
|
||||
expect_equal(attributes(bst2)$evaluation_log, attributes(bst)$evaluation_log)
|
||||
# test continuing from raw model data
|
||||
bst2 <- xgb.train(param, dtrain, nrounds = 2, watchlist, verbose = 0, xgb_model = xgb.save.raw(bst1))
|
||||
bst2 <- xgb.train(param, dtrain, nrounds = 2, evals = evals, verbose = 0, xgb_model = xgb.save.raw(bst1))
|
||||
if (!windows_flag && !solaris_flag) {
|
||||
expect_equal(xgb.save.raw(bst), xgb.save.raw(bst2))
|
||||
}
|
||||
@@ -323,7 +323,7 @@ test_that("training continuation works", {
|
||||
# test continuing from a model in file
|
||||
fname <- file.path(tempdir(), "xgboost.json")
|
||||
xgb.save(bst1, fname)
|
||||
bst2 <- xgb.train(param, dtrain, nrounds = 2, watchlist, verbose = 0, xgb_model = fname)
|
||||
bst2 <- xgb.train(param, dtrain, nrounds = 2, evals = evals, verbose = 0, xgb_model = fname)
|
||||
if (!windows_flag && !solaris_flag) {
|
||||
expect_equal(xgb.save.raw(bst), xgb.save.raw(bst2))
|
||||
}
|
||||
@@ -417,7 +417,7 @@ test_that("max_delta_step works", {
|
||||
dtrain <- xgb.DMatrix(
|
||||
agaricus.train$data, label = agaricus.train$label, nthread = n_threads
|
||||
)
|
||||
watchlist <- list(train = dtrain)
|
||||
evals <- list(train = dtrain)
|
||||
param <- list(
|
||||
objective = "binary:logistic", eval_metric = "logloss", max_depth = 2,
|
||||
nthread = n_threads,
|
||||
@@ -425,9 +425,9 @@ test_that("max_delta_step works", {
|
||||
)
|
||||
nrounds <- 5
|
||||
# model with no restriction on max_delta_step
|
||||
bst1 <- xgb.train(param, dtrain, nrounds, watchlist, verbose = 1)
|
||||
bst1 <- xgb.train(param, dtrain, nrounds, evals = evals, verbose = 1)
|
||||
# model with restricted max_delta_step
|
||||
bst2 <- xgb.train(param, dtrain, nrounds, watchlist, verbose = 1, max_delta_step = 1)
|
||||
bst2 <- xgb.train(param, dtrain, nrounds, evals = evals, verbose = 1, max_delta_step = 1)
|
||||
# the no-restriction model is expected to have consistently lower loss during the initial iterations
|
||||
expect_true(all(attributes(bst1)$evaluation_log$train_logloss < attributes(bst2)$evaluation_log$train_logloss))
|
||||
expect_lt(mean(attributes(bst1)$evaluation_log$train_logloss) / mean(attributes(bst2)$evaluation_log$train_logloss), 0.8)
|
||||
@@ -444,7 +444,7 @@ test_that("colsample_bytree works", {
|
||||
colnames(test_x) <- paste0("Feature_", sprintf("%03d", 1:100))
|
||||
dtrain <- xgb.DMatrix(train_x, label = train_y, nthread = n_threads)
|
||||
dtest <- xgb.DMatrix(test_x, label = test_y, nthread = n_threads)
|
||||
watchlist <- list(train = dtrain, eval = dtest)
|
||||
evals <- list(train = dtrain, eval = dtest)
|
||||
## Use colsample_bytree = 0.01, so that roughly one out of 100 features is chosen for
|
||||
## each tree
|
||||
param <- list(
|
||||
@@ -453,7 +453,7 @@ test_that("colsample_bytree works", {
|
||||
eval_metric = "auc"
|
||||
)
|
||||
set.seed(2)
|
||||
bst <- xgb.train(param, dtrain, nrounds = 100, watchlist, verbose = 0)
|
||||
bst <- xgb.train(param, dtrain, nrounds = 100, evals = evals, verbose = 0)
|
||||
xgb.importance(model = bst)
|
||||
# If colsample_bytree works properly, a variety of features should be used
|
||||
# in the 100 trees
|
||||
|
||||
@@ -19,7 +19,7 @@ ltrain <- add.noise(train$label, 0.2)
|
||||
ltest <- add.noise(test$label, 0.2)
|
||||
dtrain <- xgb.DMatrix(train$data, label = ltrain, nthread = n_threads)
|
||||
dtest <- xgb.DMatrix(test$data, label = ltest, nthread = n_threads)
|
||||
watchlist <- list(train = dtrain, test = dtest)
|
||||
evals <- list(train = dtrain, test = dtest)
|
||||
|
||||
|
||||
err <- function(label, pr) sum((pr > 0.5) != label) / length(label)
|
||||
@@ -39,7 +39,7 @@ test_that("xgb.cb.print.evaluation works as expected for xgb.train", {
|
||||
nthread = n_threads
|
||||
),
|
||||
nrounds = 10,
|
||||
watchlist = list(train = dtrain, test = dtest),
|
||||
evals = list(train = dtrain, test = dtest),
|
||||
callbacks = list(xgb.cb.print.evaluation(period = 1))
|
||||
)
|
||||
})
|
||||
@@ -57,7 +57,7 @@ test_that("xgb.cb.print.evaluation works as expected for xgb.train", {
|
||||
nthread = n_threads
|
||||
),
|
||||
nrounds = 10,
|
||||
watchlist = list(train = dtrain, test = dtest),
|
||||
evals = list(train = dtrain, test = dtest),
|
||||
callbacks = list(xgb.cb.print.evaluation(period = 2))
|
||||
)
|
||||
})
|
||||
@@ -117,7 +117,7 @@ test_that("xgb.cb.evaluation.log works as expected for xgb.train", {
|
||||
),
|
||||
nrounds = 10,
|
||||
verbose = FALSE,
|
||||
watchlist = list(train = dtrain, test = dtest),
|
||||
evals = list(train = dtrain, test = dtest),
|
||||
callbacks = list(xgb.cb.evaluation.log())
|
||||
)
|
||||
logs <- attributes(model)$evaluation_log
|
||||
@@ -155,7 +155,7 @@ param <- list(objective = "binary:logistic", eval_metric = "error",
|
||||
|
||||
test_that("can store evaluation_log without printing", {
|
||||
expect_silent(
|
||||
bst <- xgb.train(param, dtrain, nrounds = 10, watchlist, eta = 1, verbose = 0)
|
||||
bst <- xgb.train(param, dtrain, nrounds = 10, evals = evals, eta = 1, verbose = 0)
|
||||
)
|
||||
expect_false(is.null(attributes(bst)$evaluation_log))
|
||||
expect_false(is.null(attributes(bst)$evaluation_log$train_error))
|
||||
@@ -166,14 +166,14 @@ test_that("xgb.cb.reset.parameters works as expected", {
|
||||
|
||||
# fixed eta
|
||||
set.seed(111)
|
||||
bst0 <- xgb.train(param, dtrain, nrounds = 2, watchlist, eta = 0.9, verbose = 0)
|
||||
bst0 <- xgb.train(param, dtrain, nrounds = 2, evals = evals, eta = 0.9, verbose = 0)
|
||||
expect_false(is.null(attributes(bst0)$evaluation_log))
|
||||
expect_false(is.null(attributes(bst0)$evaluation_log$train_error))
|
||||
|
||||
# same eta but re-set as a vector parameter in the callback
|
||||
set.seed(111)
|
||||
my_par <- list(eta = c(0.9, 0.9))
|
||||
bst1 <- xgb.train(param, dtrain, nrounds = 2, watchlist, verbose = 0,
|
||||
bst1 <- xgb.train(param, dtrain, nrounds = 2, evals = evals, verbose = 0,
|
||||
callbacks = list(xgb.cb.reset.parameters(my_par)))
|
||||
expect_false(is.null(attributes(bst1)$evaluation_log$train_error))
|
||||
expect_equal(attributes(bst0)$evaluation_log$train_error,
|
||||
@@ -182,7 +182,7 @@ test_that("xgb.cb.reset.parameters works as expected", {
|
||||
# same eta but re-set via a function in the callback
|
||||
set.seed(111)
|
||||
my_par <- list(eta = function(itr, itr_end) 0.9)
|
||||
bst2 <- xgb.train(param, dtrain, nrounds = 2, watchlist, verbose = 0,
|
||||
bst2 <- xgb.train(param, dtrain, nrounds = 2, evals = evals, verbose = 0,
|
||||
callbacks = list(xgb.cb.reset.parameters(my_par)))
|
||||
expect_false(is.null(attributes(bst2)$evaluation_log$train_error))
|
||||
expect_equal(attributes(bst0)$evaluation_log$train_error,
|
||||
@@ -191,7 +191,7 @@ test_that("xgb.cb.reset.parameters works as expected", {
|
||||
# different eta re-set as a vector parameter in the callback
|
||||
set.seed(111)
|
||||
my_par <- list(eta = c(0.6, 0.5))
|
||||
bst3 <- xgb.train(param, dtrain, nrounds = 2, watchlist, verbose = 0,
|
||||
bst3 <- xgb.train(param, dtrain, nrounds = 2, evals = evals, verbose = 0,
|
||||
callbacks = list(xgb.cb.reset.parameters(my_par)))
|
||||
expect_false(is.null(attributes(bst3)$evaluation_log$train_error))
|
||||
expect_false(all(attributes(bst0)$evaluation_log$train_error == attributes(bst3)$evaluation_log$train_error))
|
||||
@@ -199,7 +199,7 @@ test_that("xgb.cb.reset.parameters works as expected", {
|
||||
# resetting multiple parameters at the same time runs with no error
|
||||
my_par <- list(eta = c(1., 0.5), gamma = c(1, 2), max_depth = c(4, 8))
|
||||
expect_error(
|
||||
bst4 <- xgb.train(param, dtrain, nrounds = 2, watchlist, verbose = 0,
|
||||
bst4 <- xgb.train(param, dtrain, nrounds = 2, evals = evals, verbose = 0,
|
||||
callbacks = list(xgb.cb.reset.parameters(my_par)))
|
||||
, NA) # NA = no error
|
||||
# CV works as well
|
||||
@@ -210,7 +210,7 @@ test_that("xgb.cb.reset.parameters works as expected", {
|
||||
|
||||
# expect no learning with 0 learning rate
|
||||
my_par <- list(eta = c(0., 0.))
|
||||
bstX <- xgb.train(param, dtrain, nrounds = 2, watchlist, verbose = 0,
|
||||
bstX <- xgb.train(param, dtrain, nrounds = 2, evals = evals, verbose = 0,
|
||||
callbacks = list(xgb.cb.reset.parameters(my_par)))
|
||||
expect_false(is.null(attributes(bstX)$evaluation_log$train_error))
|
||||
er <- unique(attributes(bstX)$evaluation_log$train_error)
|
||||
@@ -223,7 +223,7 @@ test_that("xgb.cb.save.model works as expected", {
|
||||
files <- unname(sapply(files, function(f) file.path(tempdir(), f)))
|
||||
for (f in files) if (file.exists(f)) file.remove(f)
|
||||
|
||||
bst <- xgb.train(param, dtrain, nrounds = 2, watchlist, eta = 1, verbose = 0,
|
||||
bst <- xgb.train(param, dtrain, nrounds = 2, evals = evals, eta = 1, verbose = 0,
|
||||
save_period = 1, save_name = file.path(tempdir(), "xgboost_%02d.json"))
|
||||
expect_true(file.exists(files[1]))
|
||||
expect_true(file.exists(files[2]))
|
||||
@@ -239,7 +239,7 @@ test_that("xgb.cb.save.model works as expected", {
|
||||
expect_equal(xgb.save.raw(bst), xgb.save.raw(b2))
|
||||
|
||||
# save_period = 0 saves the last iteration's model
|
||||
bst <- xgb.train(param, dtrain, nrounds = 2, watchlist, eta = 1, verbose = 0,
|
||||
bst <- xgb.train(param, dtrain, nrounds = 2, evals = evals, eta = 1, verbose = 0,
|
||||
save_period = 0, save_name = file.path(tempdir(), 'xgboost.json'))
|
||||
expect_true(file.exists(files[3]))
|
||||
b2 <- xgb.load(files[3])
|
||||
@@ -252,7 +252,7 @@ test_that("xgb.cb.save.model works as expected", {
|
||||
test_that("early stopping xgb.train works", {
|
||||
set.seed(11)
|
||||
expect_output(
|
||||
bst <- xgb.train(param, dtrain, nrounds = 20, watchlist, eta = 0.3,
|
||||
bst <- xgb.train(param, dtrain, nrounds = 20, evals = evals, eta = 0.3,
|
||||
early_stopping_rounds = 3, maximize = FALSE)
|
||||
, "Stopping. Best iteration")
|
||||
expect_false(is.null(xgb.attr(bst, "best_iteration")))
|
||||
@@ -266,7 +266,7 @@ test_that("early stopping xgb.train works", {
|
||||
|
||||
set.seed(11)
|
||||
expect_silent(
|
||||
bst0 <- xgb.train(param, dtrain, nrounds = 20, watchlist, eta = 0.3,
|
||||
bst0 <- xgb.train(param, dtrain, nrounds = 20, evals = evals, eta = 0.3,
|
||||
early_stopping_rounds = 3, maximize = FALSE, verbose = 0)
|
||||
)
|
||||
expect_equal(attributes(bst)$evaluation_log, attributes(bst0)$evaluation_log)
|
||||
@@ -282,7 +282,7 @@ test_that("early stopping xgb.train works", {
|
||||
test_that("early stopping using a specific metric works", {
|
||||
set.seed(11)
|
||||
expect_output(
|
||||
bst <- xgb.train(param[-2], dtrain, nrounds = 20, watchlist, eta = 0.6,
|
||||
bst <- xgb.train(param[-2], dtrain, nrounds = 20, evals = evals, eta = 0.6,
|
||||
eval_metric = "logloss", eval_metric = "auc",
|
||||
callbacks = list(xgb.cb.early.stop(stopping_rounds = 3, maximize = FALSE,
|
||||
metric_name = 'test_logloss')))
|
||||
@@ -315,7 +315,7 @@ test_that("early stopping works with titanic", {
|
||||
nrounds = 100,
|
||||
early_stopping_rounds = 3,
|
||||
nthread = n_threads,
|
||||
watchlist = list(train = xgb.DMatrix(dtx, label = dty))
|
||||
evals = list(train = xgb.DMatrix(dtx, label = dty))
|
||||
)
|
||||
|
||||
expect_true(TRUE) # should not crash
|
||||
|
||||
@@ -12,7 +12,7 @@ dtrain <- xgb.DMatrix(
|
||||
dtest <- xgb.DMatrix(
|
||||
agaricus.test$data, label = agaricus.test$label, nthread = n_threads
|
||||
)
|
||||
watchlist <- list(eval = dtest, train = dtrain)
|
||||
evals <- list(eval = dtest, train = dtrain)
|
||||
|
||||
logregobj <- function(preds, dtrain) {
|
||||
labels <- getinfo(dtrain, "label")
|
||||
@@ -33,7 +33,7 @@ param <- list(max_depth = 2, eta = 1, nthread = n_threads,
|
||||
num_round <- 2
|
||||
|
||||
test_that("custom objective works", {
|
||||
bst <- xgb.train(param, dtrain, num_round, watchlist)
|
||||
bst <- xgb.train(param, dtrain, num_round, evals)
|
||||
expect_equal(class(bst), "xgb.Booster")
|
||||
expect_false(is.null(attributes(bst)$evaluation_log))
|
||||
expect_false(is.null(attributes(bst)$evaluation_log$eval_error))
|
||||
@@ -48,7 +48,7 @@ test_that("custom objective in CV works", {
|
||||
})
|
||||
|
||||
test_that("custom objective with early stop works", {
|
||||
bst <- xgb.train(param, dtrain, 10, watchlist)
|
||||
bst <- xgb.train(param, dtrain, 10, evals)
|
||||
expect_equal(class(bst), "xgb.Booster")
|
||||
train_log <- attributes(bst)$evaluation_log$train_error
|
||||
expect_true(all(diff(train_log) <= 0))
|
||||
@@ -66,7 +66,7 @@ test_that("custom objective using DMatrix attr works", {
|
||||
return(list(grad = grad, hess = hess))
|
||||
}
|
||||
param$objective <- logregobjattr
|
||||
bst <- xgb.train(param, dtrain, num_round, watchlist)
|
||||
bst <- xgb.train(param, dtrain, num_round, evals)
|
||||
expect_equal(class(bst), "xgb.Booster")
|
||||
})
|
||||
|
||||
|
||||
@@ -41,13 +41,13 @@ test_that("xgb.DMatrix: basic construction", {
|
||||
|
||||
params <- list(tree_method = "hist", nthread = n_threads)
|
||||
bst_fd <- xgb.train(
|
||||
params, nrounds = 8, fd, watchlist = list(train = fd)
|
||||
params, nrounds = 8, fd, evals = list(train = fd)
|
||||
)
|
||||
bst_dgr <- xgb.train(
|
||||
params, nrounds = 8, fdgr, watchlist = list(train = fdgr)
|
||||
params, nrounds = 8, fdgr, evals = list(train = fdgr)
|
||||
)
|
||||
bst_dgc <- xgb.train(
|
||||
params, nrounds = 8, fdgc, watchlist = list(train = fdgc)
|
||||
params, nrounds = 8, fdgc, evals = list(train = fdgc)
|
||||
)
|
||||
|
||||
raw_fd <- xgb.save.raw(bst_fd, raw_format = "ubj")
|
||||
|
||||
@@ -14,19 +14,19 @@ test_that("gblinear works", {
|
||||
|
||||
param <- list(objective = "binary:logistic", eval_metric = "error", booster = "gblinear",
|
||||
nthread = n_threads, eta = 0.8, alpha = 0.0001, lambda = 0.0001)
|
||||
watchlist <- list(eval = dtest, train = dtrain)
|
||||
evals <- list(eval = dtest, train = dtrain)
|
||||
|
||||
n <- 5 # iterations
|
||||
ERR_UL <- 0.005 # upper limit for the test set error
|
||||
VERB <- 0 # chatterbox switch
|
||||
|
||||
param$updater <- 'shotgun'
|
||||
bst <- xgb.train(param, dtrain, n, watchlist, verbose = VERB, feature_selector = 'shuffle')
|
||||
bst <- xgb.train(param, dtrain, n, evals, verbose = VERB, feature_selector = 'shuffle')
|
||||
ypred <- predict(bst, dtest)
|
||||
expect_equal(length(getinfo(dtest, 'label')), 1611)
|
||||
expect_lt(attributes(bst)$evaluation_log$eval_error[n], ERR_UL)
|
||||
|
||||
bst <- xgb.train(param, dtrain, n, watchlist, verbose = VERB, feature_selector = 'cyclic',
|
||||
bst <- xgb.train(param, dtrain, n, evals, verbose = VERB, feature_selector = 'cyclic',
|
||||
callbacks = list(xgb.cb.gblinear.history()))
|
||||
expect_lt(attributes(bst)$evaluation_log$eval_error[n], ERR_UL)
|
||||
h <- xgb.gblinear.history(bst)
|
||||
@@ -34,16 +34,16 @@ test_that("gblinear works", {
|
||||
expect_is(h, "matrix")
|
||||
|
||||
param$updater <- 'coord_descent'
|
||||
bst <- xgb.train(param, dtrain, n, watchlist, verbose = VERB, feature_selector = 'cyclic')
|
||||
bst <- xgb.train(param, dtrain, n, evals, verbose = VERB, feature_selector = 'cyclic')
|
||||
expect_lt(attributes(bst)$evaluation_log$eval_error[n], ERR_UL)
|
||||
|
||||
bst <- xgb.train(param, dtrain, n, watchlist, verbose = VERB, feature_selector = 'shuffle')
|
||||
bst <- xgb.train(param, dtrain, n, evals, verbose = VERB, feature_selector = 'shuffle')
|
||||
expect_lt(attributes(bst)$evaluation_log$eval_error[n], ERR_UL)
|
||||
|
||||
bst <- xgb.train(param, dtrain, 2, watchlist, verbose = VERB, feature_selector = 'greedy')
|
||||
bst <- xgb.train(param, dtrain, 2, evals, verbose = VERB, feature_selector = 'greedy')
|
||||
expect_lt(attributes(bst)$evaluation_log$eval_error[2], ERR_UL)
|
||||
|
||||
bst <- xgb.train(param, dtrain, n, watchlist, verbose = VERB, feature_selector = 'thrifty',
|
||||
bst <- xgb.train(param, dtrain, n, evals, verbose = VERB, feature_selector = 'thrifty',
|
||||
top_k = 50, callbacks = list(xgb.cb.gblinear.history(sparse = TRUE)))
|
||||
expect_lt(attributes(bst)$evaluation_log$eval_error[n], ERR_UL)
|
||||
h <- xgb.gblinear.history(bst)
|
||||
|
||||
@@ -15,7 +15,7 @@ test_that('Test ranking with unweighted data', {
|
||||
|
||||
params <- list(eta = 1, tree_method = 'exact', objective = 'rank:pairwise', max_depth = 1,
|
||||
eval_metric = 'auc', eval_metric = 'aucpr', nthread = n_threads)
|
||||
bst <- xgb.train(params, dtrain, nrounds = 10, watchlist = list(train = dtrain))
|
||||
bst <- xgb.train(params, dtrain, nrounds = 10, evals = list(train = dtrain))
|
||||
# Check if the metric is monotone increasing
|
||||
expect_true(all(diff(attributes(bst)$evaluation_log$train_auc) >= 0))
|
||||
expect_true(all(diff(attributes(bst)$evaluation_log$train_aucpr) >= 0))
|
||||
@@ -39,7 +39,7 @@ test_that('Test ranking with weighted data', {
|
||||
eta = 1, tree_method = "exact", objective = "rank:pairwise", max_depth = 1,
|
||||
eval_metric = "auc", eval_metric = "aucpr", nthread = n_threads
|
||||
)
|
||||
bst <- xgb.train(params, dtrain, nrounds = 10, watchlist = list(train = dtrain))
|
||||
bst <- xgb.train(params, dtrain, nrounds = 10, evals = list(train = dtrain))
|
||||
# Check if the metric is monotone increasing
|
||||
expect_true(all(diff(attributes(bst)$evaluation_log$train_auc) >= 0))
|
||||
expect_true(all(diff(attributes(bst)$evaluation_log$train_aucpr) >= 0))
|
||||
|
||||
@@ -17,7 +17,7 @@ dtest <- xgb.DMatrix(
|
||||
win32_flag <- .Platform$OS.type == "windows" && .Machine$sizeof.pointer != 8
|
||||
|
||||
test_that("updating the model works", {
|
||||
watchlist <- list(train = dtrain, test = dtest)
|
||||
evals <- list(train = dtrain, test = dtest)
|
||||
|
||||
# no-subsampling
|
||||
p1 <- list(
|
||||
@@ -25,19 +25,19 @@ test_that("updating the model works", {
|
||||
updater = "grow_colmaker,prune"
|
||||
)
|
||||
set.seed(11)
|
||||
bst1 <- xgb.train(p1, dtrain, nrounds = 10, watchlist, verbose = 0)
|
||||
bst1 <- xgb.train(p1, dtrain, nrounds = 10, evals = evals, verbose = 0)
|
||||
tr1 <- xgb.model.dt.tree(model = bst1)
|
||||
|
||||
# with subsampling
|
||||
p2 <- modifyList(p1, list(subsample = 0.1))
|
||||
set.seed(11)
|
||||
bst2 <- xgb.train(p2, dtrain, nrounds = 10, watchlist, verbose = 0)
|
||||
bst2 <- xgb.train(p2, dtrain, nrounds = 10, evals = evals, verbose = 0)
|
||||
tr2 <- xgb.model.dt.tree(model = bst2)
|
||||
|
||||
# the same no-subsampling boosting with an extra 'refresh' updater:
|
||||
p1r <- modifyList(p1, list(updater = 'grow_colmaker,prune,refresh', refresh_leaf = FALSE))
|
||||
set.seed(11)
|
||||
bst1r <- xgb.train(p1r, dtrain, nrounds = 10, watchlist, verbose = 0)
|
||||
bst1r <- xgb.train(p1r, dtrain, nrounds = 10, evals = evals, verbose = 0)
|
||||
tr1r <- xgb.model.dt.tree(model = bst1r)
|
||||
# all should be the same when no subsampling
|
||||
expect_equal(attributes(bst1)$evaluation_log, attributes(bst1r)$evaluation_log)
|
||||
@@ -53,7 +53,7 @@ test_that("updating the model works", {
|
||||
# the same boosting with subsampling with an extra 'refresh' updater:
|
||||
p2r <- modifyList(p2, list(updater = 'grow_colmaker,prune,refresh', refresh_leaf = FALSE))
|
||||
set.seed(11)
|
||||
bst2r <- xgb.train(p2r, dtrain, nrounds = 10, watchlist, verbose = 0)
|
||||
bst2r <- xgb.train(p2r, dtrain, nrounds = 10, evals = evals, verbose = 0)
|
||||
tr2r <- xgb.model.dt.tree(model = bst2r)
|
||||
# should be the same evaluation but different gains and larger cover
|
||||
expect_equal(attributes(bst2)$evaluation_log, attributes(bst2r)$evaluation_log)
|
||||
@@ -66,7 +66,7 @@ test_that("updating the model works", {
|
||||
# process type 'update' for no-subsampling model, refreshing the tree stats AND leaves from training data:
|
||||
set.seed(123)
|
||||
p1u <- modifyList(p1, list(process_type = 'update', updater = 'refresh', refresh_leaf = TRUE))
|
||||
bst1u <- xgb.train(p1u, dtrain, nrounds = 10, watchlist, verbose = 0, xgb_model = bst1)
|
||||
bst1u <- xgb.train(p1u, dtrain, nrounds = 10, evals = evals, verbose = 0, xgb_model = bst1)
|
||||
tr1u <- xgb.model.dt.tree(model = bst1u)
|
||||
# all should be the same when no subsampling
|
||||
expect_equal(attributes(bst1)$evaluation_log, attributes(bst1u)$evaluation_log)
|
||||
@@ -79,7 +79,7 @@ test_that("updating the model works", {
|
||||
|
||||
# same thing but with a serialized model
|
||||
set.seed(123)
|
||||
bst1u <- xgb.train(p1u, dtrain, nrounds = 10, watchlist, verbose = 0, xgb_model = xgb.save.raw(bst1))
|
||||
bst1u <- xgb.train(p1u, dtrain, nrounds = 10, evals = evals, verbose = 0, xgb_model = xgb.save.raw(bst1))
|
||||
tr1u <- xgb.model.dt.tree(model = bst1u)
|
||||
# all should be the same when no subsampling
|
||||
expect_equal(attributes(bst1)$evaluation_log, attributes(bst1u)$evaluation_log)
|
||||
@@ -87,7 +87,7 @@ test_that("updating the model works", {
|
||||
|
||||
# process type 'update' for model with subsampling, refreshing only the tree stats from training data:
|
||||
p2u <- modifyList(p2, list(process_type = 'update', updater = 'refresh', refresh_leaf = FALSE))
|
||||
bst2u <- xgb.train(p2u, dtrain, nrounds = 10, watchlist, verbose = 0, xgb_model = bst2)
|
||||
bst2u <- xgb.train(p2u, dtrain, nrounds = 10, evals = evals, verbose = 0, xgb_model = bst2)
|
||||
tr2u <- xgb.model.dt.tree(model = bst2u)
|
||||
# should be the same evaluation but different gains and larger cover
|
||||
expect_equal(attributes(bst2)$evaluation_log, attributes(bst2u)$evaluation_log)
|
||||
@@ -102,7 +102,7 @@ test_that("updating the model works", {
|
||||
|
||||
# process type 'update' for no-subsampling model, refreshing only the tree stats from TEST data:
|
||||
p1ut <- modifyList(p1, list(process_type = 'update', updater = 'refresh', refresh_leaf = FALSE))
|
||||
bst1ut <- xgb.train(p1ut, dtest, nrounds = 10, watchlist, verbose = 0, xgb_model = bst1)
|
||||
bst1ut <- xgb.train(p1ut, dtest, nrounds = 10, evals = evals, verbose = 0, xgb_model = bst1)
|
||||
tr1ut <- xgb.model.dt.tree(model = bst1ut)
|
||||
# should be the same evaluations but different gains and smaller cover (test data is smaller)
|
||||
expect_equal(attributes(bst1)$evaluation_log, attributes(bst1ut)$evaluation_log)
|
||||
@@ -115,18 +115,18 @@ test_that("updating works for multiclass & multitree", {
|
||||
dtr <- xgb.DMatrix(
|
||||
as.matrix(iris[, -5]), label = as.numeric(iris$Species) - 1, nthread = n_threads
|
||||
)
|
||||
watchlist <- list(train = dtr)
|
||||
evals <- list(train = dtr)
|
||||
p0 <- list(max_depth = 2, eta = 0.5, nthread = n_threads, subsample = 0.6,
|
||||
objective = "multi:softprob", num_class = 3, num_parallel_tree = 2,
|
||||
base_score = 0)
|
||||
set.seed(121)
|
||||
bst0 <- xgb.train(p0, dtr, 5, watchlist, verbose = 0)
|
||||
bst0 <- xgb.train(p0, dtr, 5, evals = evals, verbose = 0)
|
||||
tr0 <- xgb.model.dt.tree(model = bst0)
|
||||
|
||||
# run update process for an original model with subsampling
|
||||
p0u <- modifyList(p0, list(process_type = 'update', updater = 'refresh', refresh_leaf = FALSE))
|
||||
bst0u <- xgb.train(p0u, dtr, nrounds = xgb.get.num.boosted.rounds(bst0),
|
||||
watchlist, xgb_model = bst0, verbose = 0)
|
||||
evals = evals, xgb_model = bst0, verbose = 0)
|
||||
tr0u <- xgb.model.dt.tree(model = bst0u)
|
||||
|
||||
# should be the same evaluation but different gains and larger cover
|
||||
|
||||
Reference in New Issue
Block a user