Commit 301e0a7c authored by Guolin Ke's avatar Guolin Ke
Browse files

check num_boost_round in python/R package.

parent 5a89a76d
...@@ -107,6 +107,10 @@ lgb.cv <- function(params = list(), ...@@ -107,6 +107,10 @@ lgb.cv <- function(params = list(),
params <- lgb.check.eval(params, eval) params <- lgb.check.eval(params, eval)
fobj <- NULL fobj <- NULL
feval <- NULL feval <- NULL
if (nrounds <= 0) {
stop("nrounds should be greater than zero")
}
# Check for objective (function or not) # Check for objective (function or not)
if (is.function(params$objective)) { if (is.function(params$objective)) {
......
...@@ -83,6 +83,10 @@ lgb.train <- function(params = list(), ...@@ -83,6 +83,10 @@ lgb.train <- function(params = list(),
fobj <- NULL fobj <- NULL
feval <- NULL feval <- NULL
if (nrounds <= 0) {
stop("nrounds should be greater than zero")
}
# Check for objective (function or not) # Check for objective (function or not)
if (is.function(params$objective)) { if (is.function(params$objective)) {
fobj <- params$objective fobj <- params$objective
......
...@@ -18,7 +18,9 @@ lightgbm <- function(data, ...@@ -18,7 +18,9 @@ lightgbm <- function(data,
# Set data to a temporary variable # Set data to a temporary variable
dtrain <- data 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 # Check whether data is lgb.Dataset, if not then create lgb.Dataset manually
if (!lgb.is.Dataset(dtrain)) { if (!lgb.is.Dataset(dtrain)) {
dtrain <- lgb.Dataset(data, label = label, weight = weight) dtrain <- lgb.Dataset(data, label = label, weight = weight)
......
...@@ -104,6 +104,8 @@ def train(params, train_set, num_boost_round=100, ...@@ -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)) warnings.warn("Found `{}` in params. Will use it instead of argument".format(alias))
break break
if num_boost_round <= 0:
raise ValueError("num_boost_round should be greater than zero.")
if isinstance(init_model, string_type): if isinstance(init_model, string_type):
predictor = _InnerPredictor(model_file=init_model) predictor = _InnerPredictor(model_file=init_model)
elif isinstance(init_model, Booster): elif isinstance(init_model, Booster):
...@@ -394,6 +396,8 @@ def cv(params, train_set, num_boost_round=100, ...@@ -394,6 +396,8 @@ def cv(params, train_set, num_boost_round=100,
early_stopping_rounds = params.pop(alias) early_stopping_rounds = params.pop(alias)
break break
if num_boost_round <= 0:
raise ValueError("num_boost_round should be greater than zero.")
if isinstance(init_model, string_type): if isinstance(init_model, string_type):
predictor = _InnerPredictor(model_file=init_model) predictor = _InnerPredictor(model_file=init_model)
elif isinstance(init_model, Booster): elif isinstance(init_model, Booster):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment