Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
bca716cc
Unverified
Commit
bca716cc
authored
Sep 04, 2023
by
david-cortes
Committed by
GitHub
Sep 04, 2023
Browse files
[R-package] Fix misdetected objective when passing `lgb.Dataset` instance to `lightgbm()` (#6005)
parent
7e34d23c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
2 deletions
+20
-2
R-package/R/lightgbm.R
R-package/R/lightgbm.R
+4
-1
R-package/man/lightgbm.Rd
R-package/man/lightgbm.Rd
+1
-1
R-package/tests/testthat/test_basic.R
R-package/tests/testthat/test_basic.R
+15
-0
No files found.
R-package/R/lightgbm.R
View file @
bca716cc
...
...
@@ -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
...
...
R-package/man/lightgbm.Rd
View file @
bca716cc
...
...
@@ -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}}
...
...
R-package/tests/testthat/test_basic.R
View file @
bca716cc
...
...
@@ -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"
)
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment