Skip to content

Commit

Permalink
check num_boost_round in python/R package.
Browse files Browse the repository at this point in the history
  • Loading branch information
guolinke committed Dec 24, 2017
1 parent 5a89a76 commit 301e0a7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions R-package/R/lgb.cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ lgb.cv <- function(params = list(),
params <- lgb.check.eval(params, eval)
fobj <- NULL
feval <- NULL

if (nrounds <= 0) {
stop("nrounds should be greater than zero")
}

# Check for objective (function or not)
if (is.function(params$objective)) {
Expand Down
4 changes: 4 additions & 0 deletions R-package/R/lgb.train.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ lgb.train <- function(params = list(),
fobj <- NULL
feval <- NULL

if (nrounds <= 0) {
stop("nrounds should be greater than zero")
}

# Check for objective (function or not)
if (is.function(params$objective)) {
fobj <- params$objective
Expand Down
4 changes: 3 additions & 1 deletion R-package/R/lightgbm.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ lightgbm <- function(data,

# Set data to a temporary variable
dtrain <- data

if (nrounds <= 0) {
stop("nrounds should be greater than zero")
}
# Check whether data is lgb.Dataset, if not then create lgb.Dataset manually
if (!lgb.is.Dataset(dtrain)) {
dtrain <- lgb.Dataset(data, label = label, weight = weight)
Expand Down
4 changes: 4 additions & 0 deletions python-package/lightgbm/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def train(params, train_set, num_boost_round=100,
warnings.warn("Found `{}` in params. Will use it instead of argument".format(alias))
break

if num_boost_round <= 0:
raise ValueError("num_boost_round should be greater than zero.")
if isinstance(init_model, string_type):
predictor = _InnerPredictor(model_file=init_model)
elif isinstance(init_model, Booster):
Expand Down Expand Up @@ -394,6 +396,8 @@ def cv(params, train_set, num_boost_round=100,
early_stopping_rounds = params.pop(alias)
break

if num_boost_round <= 0:
raise ValueError("num_boost_round should be greater than zero.")
if isinstance(init_model, string_type):
predictor = _InnerPredictor(model_file=init_model)
elif isinstance(init_model, Booster):
Expand Down

0 comments on commit 301e0a7

Please sign in to comment.