Unverified Commit a6d1f198 authored by Nikita Titov's avatar Nikita Titov Committed by GitHub
Browse files

[R-package] Fix custom objective detection in `print.lgb.Booster()` (#4941)

* Update lgb.Booster.R

* Update lgb.cv.R

* Update lgb.train.R

* Update lgb.Booster.R
parent db045f40
...@@ -864,12 +864,13 @@ print.lgb.Booster <- function(x, ...) { ...@@ -864,12 +864,13 @@ print.lgb.Booster <- function(x, ...) {
if (obj == "none") { if (obj == "none") {
obj <- "custom" obj <- "custom"
} }
if (x$.__enclos_env__$private$num_class == 1L) { num_class <- x$.__enclos_env__$private$num_class
if (num_class == 1L) {
cat(sprintf("Objective: %s\n", obj)) cat(sprintf("Objective: %s\n", obj))
} else { } else {
cat(sprintf("Objective: %s (%d classes)\n" cat(sprintf("Objective: %s (%d classes)\n"
, obj , obj
, x$.__enclos_env__$private$num_class)) , num_class))
} }
} else { } else {
cat("(Booster handle is invalid)\n") cat("(Booster handle is invalid)\n")
......
...@@ -141,7 +141,7 @@ lgb.cv <- function(params = list() ...@@ -141,7 +141,7 @@ lgb.cv <- function(params = list()
fobj <- NULL fobj <- NULL
if (is.function(params$objective)) { if (is.function(params$objective)) {
fobj <- params$objective fobj <- params$objective
params$objective <- "NONE" params$objective <- "none"
} }
# If eval is a single function, store it as a 1-element list # If eval is a single function, store it as a 1-element list
......
...@@ -109,7 +109,7 @@ lgb.train <- function(params = list(), ...@@ -109,7 +109,7 @@ lgb.train <- function(params = list(),
fobj <- NULL fobj <- NULL
if (is.function(params$objective)) { if (is.function(params$objective)) {
fobj <- params$objective fobj <- params$objective
params$objective <- "NONE" params$objective <- "none"
} }
# If eval is a single function, store it as a 1-element list # If eval is a single function, store it as a 1-element list
......
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