如何在xgboost中关闭silent = 1?

时间:2018-02-22 12:17:09

标签: r xgboost

我正在尝试训练一个xgboost模型并且traing似乎工作但我无法设置将参数silent设置为0,即打印训练迭代。我使用下面的代码:

NullWebViewFactoryProvider

得到这个回报:

param <- list(max_depth = 2, eta = 0.005, nthread = 2, objective = "multi:softprob", eval_metric = "auc", num_class = 3, verbose = 2, silent = 0)

xgb.train(param, data = test_matrix_1, nrounds = 10, print_every_n = 1)

4 个答案:

答案 0 :(得分:1)

如果您要关闭 services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); (请参阅verbose),则需要从param列表中删除silent = 1

首先

其次您需要?xgboost参数,因为您担心在学习时观察eval_metric。它能够学习第一个数据集并在第二个数据集上测试其模型(更多信息请参考watchlist)。 e.g。

?xgboost

现在可以用以下方式完成示例实现 -

watchlist <- list(train=dtrain, test=dtest)

答案 1 :(得分:0)

尝试options(warn=-1, echo=FALSE, verbose=FALSE),您还可以查看.Options

中的其他选项

答案 2 :(得分:0)

您不使用R中的silent参数 您使用verbose参数。

以下是verbose = 0, 1 or 2

的示例
# verbose = 0, no message
bst <- xgboost(data = dtrain, max.depth = 2, eta = 1, nthread = 2, nround = 2, objective = "binary:logistic", verbose = 0)

# verbose = 1, print evaluation metric
bst <- xgboost(data = dtrain, max.depth = 2, eta = 1, nthread = 2, nround = 2, objective = "binary:logistic", verbose = 1)

## [0]  train-error:0.046522
## [1]  train-error:0.022263

# verbose = 2, also print information about tree
bst <- xgboost(data = dtrain, max.depth = 2, eta = 1, nthread = 2, nround = 2, objective = "binary:logistic", verbose = 2)

## [11:41:01] amalgamation/../src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 6 extra nodes, 0 pruned nodes, max_depth=2
## [0]  train-error:0.046522
## [11:41:01] amalgamation/../src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 4 extra nodes, 0 pruned nodes, max_depth=2
## [1]  train-error:0.022263

答案 3 :(得分:0)

这种解决方法对我有用:

将数据转换为包含标签和数据的列表,作为Matrix包中的CsparseMatrix。

test_matrix_3 <- list(data = as(training_data, "CsparseMatrix"), label = label)

之后这个功能运行良好。

xgboost(data = test_matrix_3$data, label = test_matrix_3$label, 
                 max.depth = 4, eta = 1, nthread = 2, nround = 500, objective = "multi:softmax", num_class = 3, eval.error = "auc")