From 31d0e8f65d42c6e65ef0a0eb89b4353a582ef69d Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Fri, 9 Jan 2015 11:14:08 +0100 Subject: [PATCH] better doc of dump function --- R-package/R/xgb.dump.R | 10 +++++++--- R-package/man/xgb.dump.Rd | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/R-package/R/xgb.dump.R b/R-package/R/xgb.dump.R index ceb68c1a3..f73850883 100644 --- a/R-package/R/xgb.dump.R +++ b/R-package/R/xgb.dump.R @@ -6,7 +6,7 @@ #' @importFrom stringr str_split #' @importFrom stringr str_replace #' @param model the model object. -#' @param fname the name of the text file where to save the model. If not provided or set to \code{NULL} the function will return the model as a \code{character} vector. +#' @param fname the name of the text file where to save the model text dump. If not provided or set to \code{NULL} the function will return the model as a \code{character} vector. #' @param fmap feature map file representing the type of feature. #' Detailed description could be found at #' \url{https://github.com/tqchen/xgboost/wiki/Binary-Classification#dump-model}. @@ -28,15 +28,19 @@ #' test <- agaricus.test #' bst <- xgboost(data = train$data, label = train$label, max.depth = 2, #' eta = 1, nround = 2,objective = "binary:logistic") +#' # save the model in file 'xgb.model.dump' #' xgb.dump(bst, 'xgb.model.dump') +#' +#' # print the model without saving it to a file +#' print(xgb.dump(bst)) #' @export #' -xgb.dump <- function(model, fname = NULL, fmap = "", with.stats=FALSE) { +xgb.dump <- function(model = NULL, fname = NULL, fmap = "", with.stats=FALSE) { if (class(model) != "xgb.Booster") { stop("xgb.dump: first argument must be type xgb.Booster") } if (!class(fname) %in% c("character", "NULL")) { - stop("xgb.dump: second argument must be type character if provided") + stop("xgb.dump: second argument must be type character when provided") } result <- .Call("XGBoosterDumpModel_R", model, fmap, as.integer(with.stats), PACKAGE = "xgboost") diff --git a/R-package/man/xgb.dump.Rd b/R-package/man/xgb.dump.Rd index e779f32b9..6dad9ed7b 100644 --- a/R-package/man/xgb.dump.Rd +++ b/R-package/man/xgb.dump.Rd @@ -4,12 +4,12 @@ \alias{xgb.dump} \title{Save xgboost model to text file} \usage{ -xgb.dump(model, fname = NULL, fmap = "", with.stats = FALSE) +xgb.dump(model = NULL, fname = NULL, fmap = "", with.stats = FALSE) } \arguments{ \item{model}{the model object.} -\item{fname}{the name of the text file where to save the model. If not provided or set to \code{NULL} the function will return the model as a \code{character} vector.} +\item{fname}{the name of the text file where to save the model text dump. If not provided or set to \code{NULL} the function will return the model as a \code{character} vector.} \item{fmap}{feature map file representing the type of feature. Detailed description could be found at @@ -36,6 +36,10 @@ train <- agaricus.train test <- agaricus.test bst <- xgboost(data = train$data, label = train$label, max.depth = 2, eta = 1, nround = 2,objective = "binary:logistic") +# save the model in file 'xgb.model.dump' xgb.dump(bst, 'xgb.model.dump') + +# print the model without saving it to a file +print(xgb.dump(bst)) }