Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off silent = 1 in xgboost?

Tags:

r

xgboost

I am trying to train a xgboost model and the traing seem to work but I can't manage to set the parameter silent to 0, that is printing the training-iterations. I use the code below:

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)

And gets this in return:

##### xgb.Booster
raw: 12.2 Kb 
call:
 xgb.train(params = param, data = test_matrix_1, nrounds = 10, 
  print_every_n = 1)
params (as set within xgb.train):
 max_depth = "2", eta = "0.005", nthread = "2", objective = "multi:softprob", eval_metric = "auc", num_class = "3", verbose = "2", silent = "0", silent = "1"
xgb.attributes:
 niter
callbacks:
 cb.print.evaluation(period = print_every_n)
niter: 10
like image 323
Allan A Avatar asked Jan 27 '26 10:01

Allan A


1 Answers

First of all you need to remove verbose from param list if you want to turn off silent = 1 (refer ?xgboost).

Secondly you need watchlist parameter since you are concerned of observing eval_metric while learning. It has the ability to learn on the first dataset and test its model on the second one (for more info refer ?xgboost). e.g.

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

Now a sample implementation can be done in below manner -

library(xgboost)

#sample data
data(agaricus.train, package='xgboost')
data(agaricus.test, package='xgboost')

dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label)
dtest  <- xgb.DMatrix(agaricus.test$data, label = agaricus.test$label)
watchlist <- list(train=dtrain, test=dtest)

#training XGBoost model 
param <- list(max_depth = 2, eta = 1, nthread = 2, 
              objective = "binary:logistic", eval_metric = "auc", eval_metric="error")
fit <- xgb.train(param, data=dtrain, nrounds=10, watchlist=watchlist, verbose = 2)
like image 142
1.618 Avatar answered Jan 30 '26 00:01

1.618



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!