Skip to content

Commit

Permalink
xgb params injection
Browse files Browse the repository at this point in the history
  • Loading branch information
gtesei committed Sep 30, 2015
1 parent 25dbe51 commit 3b7b0dc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
60 changes: 40 additions & 20 deletions R-package/R/fastRegression.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ removePredictorsMakingIllConditionedSquareMatrix_IFFragileLinearModel = function
#' In the latter case only if \code{best.tuning} is \code{TRUE}.
#' @param xgb.eta custom \code{eta} parameter for \code{'xgbTreeGTJ'} and \code{'xgbTree'}.
#' In the latter case only if \code{best.tuning} is \code{TRUE}.
#' @param xgb.param custom parameters for XGBoost.
#' @param ... arguments passed to the regression routine.
#'
#' @examples
Expand Down Expand Up @@ -261,6 +262,7 @@ ff.trainAndPredict.reg = function(Ytrain ,
xgb.metric.label = 'rmsle',
xgb.foldList = NULL,
xgb.eta = NULL,
xgb.param = NULL,
... ) {

model = NULL
Expand Down Expand Up @@ -376,17 +378,26 @@ ff.trainAndPredict.reg = function(Ytrain ,
trControl = controlObject,...)
pred = as.numeric( predict(model , Xtest ) )
} else if (model.label == "xgbTreeGTJ") { ### xgbTreeGTJ
param <- list("objective" = "reg:linear" ,
"min_child_weight" = 6 ,
"subsample" = 0.7 ,
"colsample_bytree" = 0.6 ,
"scale_pos_weight" = 0.8 ,
"silent" = 1 ,
"max_depth" = 8 ,
"max_delta_step" = 2 )

param['eta'] = 0.02
if (! is.null(xgb.eta)) param['eta'] = xgb.eta
## param
param = NULL
if (! is.null(xgb.param)) {
param = xgb.param
if (! is.null(xgb.eta)) stop("xgb.eta must be NULL if xgb.param is not NULL")
} else {
param <- list("objective" = "reg:linear" ,
"min_child_weight" = 6 ,
"subsample" = 0.7 ,
"colsample_bytree" = 0.6 ,
"scale_pos_weight" = 0.8 ,
"silent" = 1 ,
"max_depth" = 8 ,
"max_delta_step" = 2 )

param['eta'] = 0.02
if (! is.null(xgb.eta)) param['eta'] = xgb.eta
}


## fix nrounds?
fix.nround = FALSE
Expand Down Expand Up @@ -425,16 +436,25 @@ ff.trainAndPredict.reg = function(Ytrain ,

} else if (model.label == "xgbTree") { ### XGBoost
if (best.tuning) {
param <- list("objective" = "reg:linear",
"gamma" = 0.7,
"max_depth" = 20,
"subsample" = 0.5 , ## suggested in ESLII
"nthread" = 10,
"min_child_weight" = 1 ,
"colsample_bytree" = 0.5,
"max_delta_step" = 1)
param['eta'] = 0.05
if (! is.null(xgb.eta)) param['eta'] = xgb.eta

## param
param = NULL
if (! is.null(xgb.param)) {
param = xgb.param
if (! is.null(xgb.eta)) stop("xgb.eta must be NULL if xgb.param is not NULL")
} else {
param <- list("objective" = "reg:linear",
"gamma" = 0.7,
"max_depth" = 20,
"subsample" = 0.5 , ## suggested in ESLII
"nthread" = 10,
"min_child_weight" = 1 ,
"colsample_bytree" = 0.5,
"max_delta_step" = 1)

param['eta'] = 0.05
if (! is.null(xgb.eta)) param['eta'] = xgb.eta
}

## fix nrounds?
fix.nround = FALSE
Expand Down
5 changes: 4 additions & 1 deletion R-package/man/ff.trainAndPredict.reg.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ ff.trainAndPredict.reg(Ytrain, Xtrain, Xtest, model.label, controlObject,
best.tuning = FALSE, verbose = FALSE,
removePredictorsMakingIllConditionedSquareMatrix_forLinearModels = TRUE,
xgb.metric.fun = RMSLE.xgb, xgb.maximize = FALSE,
xgb.metric.label = "rmsle", xgb.foldList = NULL, xgb.eta = NULL, ...)
xgb.metric.label = "rmsle", xgb.foldList = NULL, xgb.eta = NULL,
xgb.param = NULL, ...)
}
\arguments{
\item{Ytrain}{the output variable as numeric vector}
Expand Down Expand Up @@ -47,6 +48,8 @@ In the latter case only if \code{best.tuning} is \code{TRUE}.}
\item{xgb.eta}{custom \code{eta} parameter for \code{'xgbTreeGTJ'} and \code{'xgbTree'}.
In the latter case only if \code{best.tuning} is \code{TRUE}.}

\item{xgb.param}{custom parameters for XGBoost.}

\item{...}{arguments passed to the regression routine.}
}
\value{
Expand Down

0 comments on commit 3b7b0dc

Please sign in to comment.