From 7708d808cee2e008d46f601bc969a883d7bb6c66 Mon Sep 17 00:00:00 2001 From: Marc Barakat Date: Thu, 25 May 2017 14:57:01 -0400 Subject: [PATCH] fixing the early stop for maximize = T (#5915) close #4587 --- R-package/R/callback.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R-package/R/callback.R b/R-package/R/callback.R index 8766df6ffe7c..a0562386ebbc 100644 --- a/R-package/R/callback.R +++ b/R-package/R/callback.R @@ -95,7 +95,7 @@ mx.callback.early.stop <- function(train.metric = NULL, eval.metric = NULL, bad. if (!is.null(env$metric)) { if (!is.null(train.metric)) { result <- env$metric$get(env$train.metric) - if (result$value < train.metric | (maximize == TRUE & result$value > train.metric)) { + if ((maximize == F & result$value < train.metric) | (maximize == TRUE & result$value > train.metric)) { return(FALSE) } } @@ -104,7 +104,7 @@ mx.callback.early.stop <- function(train.metric = NULL, eval.metric = NULL, bad. if (!is.null(eval.metric)) { if (!is.null(env$eval.metric)) { result <- env$metric$get(env$eval.metric) - if (result$value < eval.metric | (maximize == TRUE & result$value > eval.metric)) { + if ((maximize == F & result$value < eval.metric) | (maximize == TRUE & result$value > eval.metric)) { return(FALSE) } } @@ -135,7 +135,7 @@ mx.callback.early.stop <- function(train.metric = NULL, eval.metric = NULL, bad. result <- env$metric$get(env$eval.metric) - if (result$value > mx.best.score | (maximize == TRUE & result$value < mx.best.score)) { + if ((maximize == F & result$value > mx.best.score) | (maximize == TRUE & result$value < mx.best.score)) { if (mx.best.iter == bad.steps) { if (verbose) {