Remove silent from R demos. (#5675)

* Remove silent from R demos.

* Vignettes.
This commit is contained in:
Jiaming Yuan 2020-05-19 18:20:46 +08:00 committed by GitHub
parent dd9aeb60ae
commit 7903286961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 45 additions and 56 deletions

View File

@ -11,7 +11,7 @@ watchlist <- list(eval = dtest, train = dtrain)
# #
print('start running example to start from a initial prediction') print('start running example to start from a initial prediction')
# train xgboost for 1 round # train xgboost for 1 round
param <- list(max_depth=2, eta=1, nthread = 2, silent=1, objective='binary:logistic') param <- list(max_depth=2, eta=1, nthread = 2, objective='binary:logistic')
bst <- xgb.train(param, dtrain, 1, watchlist) bst <- xgb.train(param, dtrain, 1, watchlist)
# Note: we need the margin value instead of transformed prediction in set_base_margin # Note: we need the margin value instead of transformed prediction in set_base_margin
# do predict with output_margin=TRUE, will always give you margin values before logistic transformation # do predict with output_margin=TRUE, will always give you margin values before logistic transformation

View File

@ -6,7 +6,7 @@ dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label)
dtest <- xgb.DMatrix(agaricus.test$data, label = agaricus.test$label) dtest <- xgb.DMatrix(agaricus.test$data, label = agaricus.test$label)
nrounds <- 2 nrounds <- 2
param <- list(max_depth=2, eta=1, silent=1, nthread=2, objective='binary:logistic') param <- list(max_depth=2, eta=1, nthread=2, objective='binary:logistic')
cat('running cross validation\n') cat('running cross validation\n')
# do cross validation, this will print result out as # do cross validation, this will print result out as
@ -40,7 +40,7 @@ evalerror <- function(preds, dtrain) {
return(list(metric = "error", value = err)) return(list(metric = "error", value = err))
} }
param <- list(max_depth=2, eta=1, silent=1, param <- list(max_depth=2, eta=1,
objective = logregobj, eval_metric = evalerror) objective = logregobj, eval_metric = evalerror)
# train with customized objective # train with customized objective
xgb.cv(params = param, data = dtrain, nrounds = nrounds, nfold = 5) xgb.cv(params = param, data = dtrain, nrounds = nrounds, nfold = 5)

View File

@ -5,7 +5,7 @@ data(agaricus.test, package='xgboost')
dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label) dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label)
dtest <- xgb.DMatrix(agaricus.test$data, label = agaricus.test$label) dtest <- xgb.DMatrix(agaricus.test$data, label = agaricus.test$label)
param <- list(max_depth=2, eta=1, silent=1, objective='binary:logistic') param <- list(max_depth=2, eta=1, objective='binary:logistic')
watchlist <- list(eval = dtest, train = dtrain) watchlist <- list(eval = dtest, train = dtrain)
nrounds = 2 nrounds = 2

View File

@ -10,7 +10,7 @@ data(agaricus.test, package='xgboost')
dtrain <- xgb.DMatrix(data = agaricus.train$data, label = agaricus.train$label) dtrain <- xgb.DMatrix(data = agaricus.train$data, label = agaricus.train$label)
dtest <- xgb.DMatrix(data = agaricus.test$data, label = agaricus.test$label) dtest <- xgb.DMatrix(data = agaricus.test$data, label = agaricus.test$label)
param <- list(max_depth=2, eta=1, silent=1, objective='binary:logistic') param <- list(max_depth=2, eta=1, objective='binary:logistic')
nrounds = 4 nrounds = 4
# training the model for two rounds # training the model for two rounds

View File

@ -17,8 +17,8 @@ Load xgboost model from the binary model file.
} }
\details{ \details{
The input file is expected to contain a model saved in an xgboost-internal binary format The input file is expected to contain a model saved in an xgboost-internal binary format
using either \code{\link{xgb.save}} or \code{\link{cb.save.model}} in R, or using some using either \code{\link{xgb.save}} or \code{\link{cb.save.model}} in R, or using some
appropriate methods from other xgboost interfaces. E.g., a model trained in Python and appropriate methods from other xgboost interfaces. E.g., a model trained in Python and
saved from there in xgboost format, could be loaded from R. saved from there in xgboost format, could be loaded from R.
Note: a model saved as an R-object, has to be loaded using corresponding R-methods, Note: a model saved as an R-object, has to be loaded using corresponding R-methods,
@ -29,7 +29,7 @@ data(agaricus.train, package='xgboost')
data(agaricus.test, package='xgboost') data(agaricus.test, package='xgboost')
train <- agaricus.train train <- agaricus.train
test <- agaricus.test test <- agaricus.test
bst <- xgboost(data = train$data, label = train$label, max_depth = 2, bst <- xgboost(data = train$data, label = train$label, max_depth = 2,
eta = 1, nthread = 2, nrounds = 2,objective = "binary:logistic") eta = 1, nthread = 2, nrounds = 2,objective = "binary:logistic")
xgb.save(bst, 'xgb.model') xgb.save(bst, 'xgb.model')
bst <- xgb.load('xgb.model') bst <- xgb.load('xgb.model')

View File

@ -47,15 +47,15 @@ xgboost.version <- packageDescription("xgboost")$Version
\section{Introduction} \section{Introduction}
This is an introductory document of using the \verb@xgboost@ package in R. This is an introductory document of using the \verb@xgboost@ package in R.
\verb@xgboost@ is short for eXtreme Gradient Boosting package. It is an efficient \verb@xgboost@ is short for eXtreme Gradient Boosting package. It is an efficient
and scalable implementation of gradient boosting framework by \citep{friedman2001greedy} \citep{friedman2000additive}. and scalable implementation of gradient boosting framework by \citep{friedman2001greedy} \citep{friedman2000additive}.
The package includes efficient linear model solver and tree learning algorithm. The package includes efficient linear model solver and tree learning algorithm.
It supports various objective functions, including regression, classification It supports various objective functions, including regression, classification
and ranking. The package is made to be extendible, so that users are also allowed to define their own objectives easily. It has several features: and ranking. The package is made to be extendible, so that users are also allowed to define their own objectives easily. It has several features:
\begin{enumerate} \begin{enumerate}
\item{Speed: }{\verb@xgboost@ can automatically do parallel computation on \item{Speed: }{\verb@xgboost@ can automatically do parallel computation on
Windows and Linux, with openmp. It is generally over 10 times faster than Windows and Linux, with openmp. It is generally over 10 times faster than
\verb@gbm@.} \verb@gbm@.}
\item{Input Type: }{\verb@xgboost@ takes several types of input data:} \item{Input Type: }{\verb@xgboost@ takes several types of input data:}
@ -65,9 +65,9 @@ and ranking. The package is made to be extendible, so that users are also allowe
\item{Data File: }{Local data files} \item{Data File: }{Local data files}
\item{xgb.DMatrix: }{\verb@xgboost@'s own class. Recommended.} \item{xgb.DMatrix: }{\verb@xgboost@'s own class. Recommended.}
\end{itemize} \end{itemize}
\item{Sparsity: }{\verb@xgboost@ accepts sparse input for both tree booster \item{Sparsity: }{\verb@xgboost@ accepts sparse input for both tree booster
and linear booster, and is optimized for sparse input.} and linear booster, and is optimized for sparse input.}
\item{Customization: }{\verb@xgboost@ supports customized objective function \item{Customization: }{\verb@xgboost@ supports customized objective function
and evaluation function} and evaluation function}
\item{Performance: }{\verb@xgboost@ has better performance on several different \item{Performance: }{\verb@xgboost@ has better performance on several different
datasets.} datasets.}
@ -76,8 +76,8 @@ and ranking. The package is made to be extendible, so that users are also allowe
\section{Example with Mushroom data} \section{Example with Mushroom data}
In this section, we will illustrate some common usage of \verb@xgboost@. The In this section, we will illustrate some common usage of \verb@xgboost@. The
Mushroom data is cited from UCI Machine Learning Repository. \citep{Bache+Lichman:2013} Mushroom data is cited from UCI Machine Learning Repository. \citep{Bache+Lichman:2013}
<<Training and prediction with iris>>= <<Training and prediction with iris>>=
library(xgboost) library(xgboost)
@ -85,7 +85,7 @@ data(agaricus.train, package='xgboost')
data(agaricus.test, package='xgboost') data(agaricus.test, package='xgboost')
train <- agaricus.train train <- agaricus.train
test <- agaricus.test test <- agaricus.test
bst <- xgboost(data = train$data, label = train$label, max_depth = 2, eta = 1, bst <- xgboost(data = train$data, label = train$label, max_depth = 2, eta = 1,
nrounds = 2, objective = "binary:logistic") nrounds = 2, objective = "binary:logistic")
xgb.save(bst, 'model.save') xgb.save(bst, 'model.save')
bst = xgb.load('model.save') bst = xgb.load('model.save')
@ -97,12 +97,12 @@ pred <- predict(bst, test$data)
Here we can save the model to a binary local file, and load it when needed. Here we can save the model to a binary local file, and load it when needed.
We can't inspect the trees inside. However we have another function to save the We can't inspect the trees inside. However we have another function to save the
model in plain text. model in plain text.
<<Dump Model>>= <<Dump Model>>=
xgb.dump(bst, 'model.dump') xgb.dump(bst, 'model.dump')
@ @
The output looks like The output looks like
\begin{verbatim} \begin{verbatim}
booster[0]: booster[0]:
@ -122,8 +122,8 @@ booster[1]:
\end{verbatim} \end{verbatim}
It is important to know \verb@xgboost@'s own data type: \verb@xgb.DMatrix@. It is important to know \verb@xgboost@'s own data type: \verb@xgb.DMatrix@.
It speeds up \verb@xgboost@, and is needed for advanced features such as It speeds up \verb@xgboost@, and is needed for advanced features such as
training from initial prediction value, weighted training instance. training from initial prediction value, weighted training instance.
We can use \verb@xgb.DMatrix@ to construct an \verb@xgb.DMatrix@ object: We can use \verb@xgb.DMatrix@ to construct an \verb@xgb.DMatrix@ object:
<<xgb.DMatrix>>= <<xgb.DMatrix>>=
@ -132,7 +132,7 @@ class(dtrain)
head(getinfo(dtrain,'label')) head(getinfo(dtrain,'label'))
@ @
We can also save the matrix to a binary file. Then load it simply with We can also save the matrix to a binary file. Then load it simply with
\verb@xgb.DMatrix@ \verb@xgb.DMatrix@
<<save model>>= <<save model>>=
xgb.DMatrix.save(dtrain, 'xgb.DMatrix') xgb.DMatrix.save(dtrain, 'xgb.DMatrix')
@ -163,51 +163,51 @@ evalerror <- function(preds, dtrain) {
dtest <- xgb.DMatrix(test$data, label = test$label) dtest <- xgb.DMatrix(test$data, label = test$label)
watchlist <- list(eval = dtest, train = dtrain) watchlist <- list(eval = dtest, train = dtrain)
param <- list(max_depth = 2, eta = 1, silent = 1) param <- list(max_depth = 2, eta = 1)
bst <- xgb.train(param, dtrain, nrounds = 2, watchlist, logregobj, evalerror, maximize = FALSE) bst <- xgb.train(param, dtrain, nrounds = 2, watchlist, logregobj, evalerror, maximize = FALSE)
@ @
The gradient and second order gradient is required for the output of customized The gradient and second order gradient is required for the output of customized
objective function. objective function.
We also have \verb@slice@ for row extraction. It is useful in We also have \verb@slice@ for row extraction. It is useful in
cross-validation. cross-validation.
For a walkthrough demo, please see \verb@R-package/demo/@ for further For a walkthrough demo, please see \verb@R-package/demo/@ for further
details. details.
\section{The Higgs Boson competition} \section{The Higgs Boson competition}
We have made a demo for \href{http://www.kaggle.com/c/higgs-boson}{the Higgs We have made a demo for \href{http://www.kaggle.com/c/higgs-boson}{the Higgs
Boson Machine Learning Challenge}. Boson Machine Learning Challenge}.
Here are the instructions to make a submission Here are the instructions to make a submission
\begin{enumerate} \begin{enumerate}
\item Download the \href{http://www.kaggle.com/c/higgs-boson/data}{datasets} \item Download the \href{http://www.kaggle.com/c/higgs-boson/data}{datasets}
and extract them to \verb@data/@. and extract them to \verb@data/@.
\item Run scripts under \verb@xgboost/demo/kaggle-higgs/@: \item Run scripts under \verb@xgboost/demo/kaggle-higgs/@:
\href{https://github.com/tqchen/xgboost/blob/master/demo/kaggle-higgs/higgs-train.R}{higgs-train.R} \href{https://github.com/tqchen/xgboost/blob/master/demo/kaggle-higgs/higgs-train.R}{higgs-train.R}
and \href{https://github.com/tqchen/xgboost/blob/master/demo/kaggle-higgs/higgs-pred.R}{higgs-pred.R}. and \href{https://github.com/tqchen/xgboost/blob/master/demo/kaggle-higgs/higgs-pred.R}{higgs-pred.R}.
The computation will take less than a minute on Intel i7. The computation will take less than a minute on Intel i7.
\item Go to the \href{http://www.kaggle.com/c/higgs-boson/submissions/attach}{submission page} \item Go to the \href{http://www.kaggle.com/c/higgs-boson/submissions/attach}{submission page}
and submit your result. and submit your result.
\end{enumerate} \end{enumerate}
We provide \href{https://github.com/tqchen/xgboost/blob/master/demo/kaggle-higgs/speedtest.R}{a script} We provide \href{https://github.com/tqchen/xgboost/blob/master/demo/kaggle-higgs/speedtest.R}{a script}
to compare the time cost on the higgs dataset with \verb@gbm@ and \verb@xgboost@. to compare the time cost on the higgs dataset with \verb@gbm@ and \verb@xgboost@.
The training set contains 350000 records and 30 features. The training set contains 350000 records and 30 features.
\verb@xgboost@ can automatically do parallel computation. On a machine with Intel \verb@xgboost@ can automatically do parallel computation. On a machine with Intel
i7-4700MQ and 24GB memories, we found that \verb@xgboost@ costs about 35 seconds, which is about 20 times faster i7-4700MQ and 24GB memories, we found that \verb@xgboost@ costs about 35 seconds, which is about 20 times faster
than \verb@gbm@. When we limited \verb@xgboost@ to use only one thread, it was than \verb@gbm@. When we limited \verb@xgboost@ to use only one thread, it was
still about two times faster than \verb@gbm@. still about two times faster than \verb@gbm@.
Meanwhile, the result from \verb@xgboost@ reaches Meanwhile, the result from \verb@xgboost@ reaches
\href{http://www.kaggle.com/c/higgs-boson/details/evaluation}{3.60@AMS} with a \href{http://www.kaggle.com/c/higgs-boson/details/evaluation}{3.60@AMS} with a
single model. This results stands in the single model. This results stands in the
\href{http://www.kaggle.com/c/higgs-boson/leaderboard}{top 30\%} of the \href{http://www.kaggle.com/c/higgs-boson/leaderboard}{top 30\%} of the
competition. competition.
\bibliographystyle{jss} \bibliographystyle{jss}
\nocite{*} % list uncited references \nocite{*} % list uncited references

View File

@ -21,7 +21,6 @@ param <- list("objective" = "binary:logitraw",
"bst:max_depth" = 6, "bst:max_depth" = 6,
"eval_metric" = "auc", "eval_metric" = "auc",
"eval_metric" = "ams@0.15", "eval_metric" = "ams@0.15",
"silent" = 1,
"nthread" = 16) "nthread" = 16)
watchlist <- list("train" = xgmat) watchlist <- list("train" = xgmat)
nrounds = 120 nrounds = 120
@ -30,4 +29,3 @@ bst = xgb.train(param, xgmat, nrounds, watchlist );
# save out model # save out model
xgb.save(bst, "higgs.model") xgb.save(bst, "higgs.model")
print ('finish training') print ('finish training')

View File

@ -36,7 +36,6 @@ for (i in 1:length(threads)){
"bst:max_depth" = 6, "bst:max_depth" = 6,
"eval_metric" = "auc", "eval_metric" = "auc",
"eval_metric" = "ams@0.15", "eval_metric" = "ams@0.15",
"silent" = 1,
"nthread" = thread) "nthread" = thread)
watchlist <- list("train" = xgmat) watchlist <- list("train" = xgmat)
nrounds = 120 nrounds = 120

View File

@ -71,7 +71,7 @@ Scala
import ml.dmlc.xgboost4j.scala.DMatrix import ml.dmlc.xgboost4j.scala.DMatrix
import ml.dmlc.xgboost4j.scala.XGBoost import ml.dmlc.xgboost4j.scala.XGBoost
object XGBoostScalaExample { object XGBoostScalaExample {
def main(args: Array[String]) { def main(args: Array[String]) {
// read trainining data, available at xgboost/demo/data // read trainining data, available at xgboost/demo/data

View File

@ -41,19 +41,11 @@ TEST(Logging, Basic) {
output = testing::internal::GetCapturedStderr(); output = testing::internal::GetCapturedStderr();
ASSERT_EQ(output.size(), 0); ASSERT_EQ(output.size(), 0);
args["silent"] = "True";
ConsoleLogger::Configure({args.cbegin(), args.cend()});
testing::internal::CaptureStderr();
LOG(INFO) << "Test silent parameter.";
output = testing::internal::GetCapturedStderr();
ASSERT_EQ(output.length(), 0);
testing::internal::CaptureStderr(); testing::internal::CaptureStderr();
LOG(CONSOLE) << "Test Log Console"; // ignore global setting. LOG(CONSOLE) << "Test Log Console"; // ignore global setting.
output = testing::internal::GetCapturedStderr(); output = testing::internal::GetCapturedStderr();
ASSERT_NE(output.find("Test Log Console"), std::string::npos); ASSERT_NE(output.find("Test Log Console"), std::string::npos);
args["silent"] = "False";
args["verbosity"] = "2"; // restore args["verbosity"] = "2"; // restore
ConsoleLogger::Configure({args.cbegin(), args.cend()}); ConsoleLogger::Configure({args.cbegin(), args.cend()});
} }

View File

@ -9,10 +9,10 @@ dtrain = xgb.DMatrix('../../demo/data/agaricus.txt.train')
dtest = xgb.DMatrix('../../demo/data/agaricus.txt.test') dtest = xgb.DMatrix('../../demo/data/agaricus.txt.test')
# Specify parameters via map, definition are same as c++ version # Specify parameters via map, definition are same as c++ version
param = {'max_depth': 2, 'eta': 1, 'silent': 1, 'objective': 'binary:logistic' } param = {'max_depth': 2, 'eta': 1, 'objective': 'binary:logistic'}
# Specify validations set to watch performance # Specify validations set to watch performance
watchlist = [(dtest,'eval'), (dtrain,'train')] watchlist = [(dtest, 'eval'), (dtrain, 'train')]
num_round = 20 num_round = 20
# Run training, all the features in training API is available. # Run training, all the features in training API is available.