From 9387197dc16418c4591ee7fdabfff8f22c067601 Mon Sep 17 00:00:00 2001 From: Kenichi Matsui Date: Fri, 7 Jun 2019 12:41:51 +0900 Subject: [PATCH] Simplifying if condition. --- python-package/lightgbm/callback.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/python-package/lightgbm/callback.py b/python-package/lightgbm/callback.py index 102dba4b4889..d77c06642fa7 100644 --- a/python-package/lightgbm/callback.py +++ b/python-package/lightgbm/callback.py @@ -8,7 +8,6 @@ from operator import gt, lt from .compat import range_ -from .basic import LightGBMError class EarlyStopException(Exception): @@ -228,10 +227,9 @@ def _callback(env): metric_key = env.evaluation_result_list[i][1] if metric_key.split(" ")[0] == "train": continue # train metric doesn't used on early stopping. - if first_metric_only: - if eval_metric is not None: - if metric_key != "valid {}".format(eval_metric) and metric_key != eval_metric and eval_metric != "": - continue + if first_metric_only and eval_metric is not None and metric_key != "valid {}".format(eval_metric) and \ + metric_key != eval_metric and eval_metric != "": + continue score = env.evaluation_result_list[i][2] if best_score_list[i] is None or cmp_op[i](score, best_score[i]): best_score[i] = score