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
170a9304
Unverified
Commit
170a9304
authored
Aug 04, 2023
by
david-cortes
Committed by
GitHub
Aug 04, 2023
Browse files
[R-package] Fix error when passing categorical features to lightgbm() (fixes #6000) (#6003)
parent
665c4731
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
R-package/R/lgb.train.R
R-package/R/lgb.train.R
+3
-5
R-package/tests/testthat/test_basic.R
R-package/tests/testthat/test_basic.R
+15
-0
No files found.
R-package/R/lgb.train.R
View file @
170a9304
...
...
@@ -154,6 +154,9 @@ lgb.train <- function(params = list(),
# Construct datasets, if needed
data
$
update_params
(
params
=
params
)
if
(
!
is.null
(
categorical_feature
))
{
data
$
set_categorical_feature
(
categorical_feature
)
}
data
$
construct
()
# Check interaction constraints
...
...
@@ -179,11 +182,6 @@ lgb.train <- function(params = list(),
data
$
set_colnames
(
colnames
)
}
# Write categorical features
if
(
!
is.null
(
categorical_feature
))
{
data
$
set_categorical_feature
(
categorical_feature
)
}
valid_contain_train
<-
FALSE
train_data_name
<-
"train"
reduced_valid_sets
<-
list
()
...
...
R-package/tests/testthat/test_basic.R
View file @
170a9304
...
...
@@ -3773,3 +3773,18 @@ test_that("lightgbm() model predictions retain factor levels for binary classifi
expect_true
(
is.numeric
(
pred
))
expect_false
(
any
(
pred
%in%
y
))
})
test_that
(
"lightgbm() accepts named categorical_features"
,
{
data
(
mtcars
)
y
<-
mtcars
$
mpg
x
<-
as.matrix
(
mtcars
[,
-1L
])
model
<-
lightgbm
(
x
,
y
,
categorical_feature
=
"cyl"
,
verbose
=
.LGB_VERBOSITY
,
nrounds
=
5L
,
num_threads
=
.LGB_MAX_THREADS
)
expect_true
(
length
(
model
$
params
$
categorical_feature
)
>
0L
)
})
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