Unverified Commit bca716cc authored by david-cortes's avatar david-cortes Committed by GitHub
Browse files

[R-package] Fix misdetected objective when passing `lgb.Dataset` instance to `lightgbm()` (#6005)

parent 7e34d23c
......@@ -116,7 +116,7 @@ NULL
#' \item If passing a factor with more than two variables, will use objective \code{"multiclass"}
#' (note that parameter \code{num_class} in this case will also be determined automatically from
#' \code{label}).
#' \item Otherwise, will use objective \code{"regression"}.
#' \item Otherwise (or if passing \code{lgb.Dataset} as input), will use objective \code{"regression"}.
#' }
#'
#' \emph{New in version 4.0.0}
......@@ -211,6 +211,9 @@ lightgbm <- function(data,
rm(temp)
} else {
data_processor <- NULL
if (objective == "auto") {
objective <- "regression"
}
}
# Set data to a temporary variable
......
......@@ -68,7 +68,7 @@ set to the iteration number of the best iteration.}
\item If passing a factor with more than two variables, will use objective \code{"multiclass"}
(note that parameter \code{num_class} in this case will also be determined automatically from
\code{label}).
\item Otherwise, will use objective \code{"regression"}.
\item Otherwise (or if passing \code{lgb.Dataset} as input), will use objective \code{"regression"}.
}
\emph{New in version 4.0.0}}
......
......@@ -3790,3 +3790,18 @@ test_that("lightgbm() accepts named categorical_features", {
)
expect_true(length(model$params$categorical_feature) > 0L)
})
test_that("lightgbm() correctly sets objective when passing lgb.Dataset as input", {
data(mtcars)
y <- mtcars$mpg
x <- as.matrix(mtcars[, -1L])
ds <- lgb.Dataset(x, label = y)
model <- lightgbm(
ds
, objective = "auto"
, verbose = .LGB_VERBOSITY
, nrounds = 5L
, num_threads = .LGB_MAX_THREADS
)
expect_equal(model$params$objective, "regression")
})
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