Skip to content

Commit

Permalink
added new early_stopping param alias (#2431)
Browse files Browse the repository at this point in the history
  • Loading branch information
StrikerRUS authored and guolinke committed Sep 26, 2019
1 parent be206a9 commit fe9f292
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R-package/R/lgb.cv.R
Expand Up @@ -212,7 +212,7 @@ lgb.cv <- function(params = list(),
}

# Check for early stopping passed as parameter when adding early stopping callback
early_stop <- c("early_stopping_round", "early_stopping_rounds", "early_stopping")
early_stop <- c("early_stopping_round", "early_stopping_rounds", "early_stopping", "n_iter_no_change")
if (any(names(params) %in% early_stop)) {
if (params[[which(names(params) %in% early_stop)[1]]] > 0) {
callbacks <- add.cb(callbacks, cb.early.stop(params[[which(names(params) %in% early_stop)[1]]], verbose = verbose))
Expand Down
2 changes: 1 addition & 1 deletion R-package/R/lgb.train.R
Expand Up @@ -195,7 +195,7 @@ lgb.train <- function(params = list(),
}

# Check for early stopping passed as parameter when adding early stopping callback
early_stop <- c("early_stopping_round", "early_stopping_rounds", "early_stopping")
early_stop <- c("early_stopping_round", "early_stopping_rounds", "early_stopping", "n_iter_no_change")
if (any(names(params) %in% early_stop)) {
if (params[[which(names(params) %in% early_stop)[1]]] > 0) {
callbacks <- add.cb(callbacks, cb.early.stop(params[[which(names(params) %in% early_stop)[1]]], verbose = verbose))
Expand Down
2 changes: 1 addition & 1 deletion docs/Parameters.rst
Expand Up @@ -276,7 +276,7 @@ Learning Control Parameters

- random seed for ``feature_fraction``

- ``early_stopping_round`` :raw-html:`<a id="early_stopping_round" title="Permalink to this parameter" href="#early_stopping_round">&#x1F517;&#xFE0E;</a>`, default = ``0``, type = int, aliases: ``early_stopping_rounds``, ``early_stopping``
- ``early_stopping_round`` :raw-html:`<a id="early_stopping_round" title="Permalink to this parameter" href="#early_stopping_round">&#x1F517;&#xFE0E;</a>`, default = ``0``, type = int, aliases: ``early_stopping_rounds``, ``early_stopping``, ``n_iter_no_change``

- will stop training if one metric of one validation data doesn't improve in last ``early_stopping_round`` rounds

Expand Down
2 changes: 1 addition & 1 deletion include/LightGBM/config.h
Expand Up @@ -288,7 +288,7 @@ struct Config {
// desc = random seed for ``feature_fraction``
int feature_fraction_seed = 2;

// alias = early_stopping_rounds, early_stopping
// alias = early_stopping_rounds, early_stopping, n_iter_no_change
// desc = will stop training if one metric of one validation data doesn't improve in last ``early_stopping_round`` rounds
// desc = ``<= 0`` means disable
int early_stopping_round = 0;
Expand Down
4 changes: 2 additions & 2 deletions python-package/lightgbm/engine.py
Expand Up @@ -147,7 +147,7 @@ def train(params, train_set, num_boost_round=100,
num_boost_round = params.pop(alias)
warnings.warn("Found `{}` in params. Will use it instead of argument".format(alias))
break
for alias in ["early_stopping_round", "early_stopping_rounds", "early_stopping"]:
for alias in ["early_stopping_round", "early_stopping_rounds", "early_stopping", "n_iter_no_change"]:
if alias in params:
early_stopping_rounds = params.pop(alias)
warnings.warn("Found `{}` in params. Will use it instead of argument".format(alias))
Expand Down Expand Up @@ -502,7 +502,7 @@ def cv(params, train_set, num_boost_round=100,
warnings.warn("Found `{}` in params. Will use it instead of argument".format(alias))
num_boost_round = params.pop(alias)
break
for alias in ["early_stopping_round", "early_stopping_rounds", "early_stopping"]:
for alias in ["early_stopping_round", "early_stopping_rounds", "early_stopping", "n_iter_no_change"]:
if alias in params:
warnings.warn("Found `{}` in params. Will use it instead of argument".format(alias))
early_stopping_rounds = params.pop(alias)
Expand Down
1 change: 1 addition & 0 deletions src/io/config_auto.cpp
Expand Up @@ -72,6 +72,7 @@ std::unordered_map<std::string, std::string> Config::alias_table({
{"colsample_bynode", "feature_fraction_bynode"},
{"early_stopping_rounds", "early_stopping_round"},
{"early_stopping", "early_stopping_round"},
{"n_iter_no_change", "early_stopping_round"},
{"max_tree_output", "max_delta_step"},
{"max_leaf_output", "max_delta_step"},
{"reg_alpha", "lambda_l1"},
Expand Down

0 comments on commit fe9f292

Please sign in to comment.