Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: flipMultivariates
Type: Package
Title: Multivariate models
Version: 1.2.4
Version: 1.2.5
Author: Displayr <opensource@displayr.com>
Maintainer: Displayr <opensource@displayr.com>
Description: Multivariate models (e.g. LDA, random forest, SVM) according to the flip Project conventions.
Expand Down Expand Up @@ -29,7 +29,7 @@ Imports:
rhtmlMoonPlot,
tensorflow,
utils,
xgboost (>= 1.1.1.1),
xgboost (>= 2.0.0),
verbs
Suggests:
Ckmeans.1d.dp,
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ importFrom(verbs,Sum)
importFrom(verbs,SumEachColumn)
importFrom(verbs,SumEachRow)
importFrom(verbs,SumEmptyHandling)
importFrom(xgboost,xgb.DMatrix)
importFrom(xgboost,xgb.cv)
importFrom(xgboost,xgb.ggplot.importance)
importFrom(xgboost,xgb.importance)
importFrom(xgboost,xgb.load.raw)
importFrom(xgboost,xgboost)
importFrom(xgboost,xgb.train)
31 changes: 18 additions & 13 deletions R/gradientboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' @param show.labels Shows the variable labels, as opposed to the labels, in the outputs, where a
#' variables label is an attribute (e.g., attr(foo, "label")).
#'
#' @importFrom xgboost xgboost xgb.cv
#' @importFrom xgboost xgb.DMatrix xgb.train xgb.cv
#' @importFrom flipTransformations OneHot
#' @importFrom flipU StopForUserError
#' @aliases GradientBoosting
Expand Down Expand Up @@ -106,13 +106,17 @@ GradientBoost <- GradientBoosting <- function(formula,
params.default <- list(booster = booster, objective = objective, num_class = n.class,
lambda = 0, alpha = 0, nthread = 1, eval_metric = eval.metric)

# xgboost >= 2.0 requires xgb.cv/xgb.train inputs to be xgb.DMatrix objects
# and no longer accepts data/label as raw matrices.
dtrain <- xgb.DMatrix(data = numeric.data$X, label = numeric.data$y)

if (!grid.search)
{
xval <- xgb.cv(data = numeric.data$X, label = numeric.data$y, nrounds = 1000, nfold = 10,
xval <- xgb.cv(data = dtrain, nrounds = 1000, nfold = 10,
params = params.default, early_stopping_rounds = 8, maximize = FALSE, verbose = 0)
best.rounds <- which.min(xval$evaluation_log[, xval.metric])
result <- list(original = xgboost(data = numeric.data$X, label = numeric.data$y, params = params.default,
save_period = NULL, nrounds = best.rounds, verbose = 0))
result <- list(original = xgb.train(data = dtrain, params = params.default,
save_period = NULL, nrounds = best.rounds, verbose = 0))
}
else
{
Expand All @@ -121,11 +125,13 @@ GradientBoost <- GradientBoosting <- function(formula,
for (param in names(variable.params))
all.params[param] <- variable.params[[param]]

xgbcv <- xgb.cv(data = numeric.data$X, label = numeric.data$y, params = all.params,
set.seed(seed)
xgbcv <- xgb.cv(data = dtrain, params = all.params,
nfold = cv.nfold, nrounds = n.rounds,
verbose = 0, early_stopping_rounds = 8, maximize = FALSE, seed = seed)
verbose = 0, early_stopping_rounds = 8, maximize = FALSE)

return(c(min.error = min(xgbcv$evaluation_log[, xval.metric]), rounds = xgbcv$best_iteration, all.params))
return(c(min.error = min(xgbcv$evaluation_log[, xval.metric]),
rounds = xgbcv$early_stop$best_iteration, all.params))
}

n.rounds <- 1000
Expand All @@ -147,12 +153,11 @@ GradientBoost <- GradientBoosting <- function(formula,
best.error.rounds <- search.results[best.index, "rounds"]
best.param <- as.list(search.results[best.index, -(1:2)])
set.seed(seed) # reset seed after searching
result <- list(original = xgboost(data = numeric.data$X,
label = numeric.data$y,
verbose = 0,
params = best.param,
save_period = NULL,
nrounds = best.error.rounds))
result <- list(original = xgb.train(data = dtrain,
verbose = 0,
params = best.param,
save_period = NULL,
nrounds = best.error.rounds))
}

####################################################################
Expand Down
Loading