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
fa6d3565
Unverified
Commit
fa6d3565
authored
Apr 28, 2021
by
James Lamb
Committed by
GitHub
Apr 28, 2021
Browse files
[R-package] avoid misleading warnings when using interaction constraints (fixes #4108) (#4232)
parent
086f0785
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
7 deletions
+20
-7
R-package/R/lgb.cv.R
R-package/R/lgb.cv.R
+9
-1
R-package/R/lgb.train.R
R-package/R/lgb.train.R
+6
-1
R-package/R/utils.R
R-package/R/utils.R
+5
-5
No files found.
R-package/R/lgb.cv.R
View file @
fa6d3565
...
...
@@ -166,6 +166,11 @@ lgb.cv <- function(params = list()
}
end_iteration
<-
begin_iteration
+
params
[[
"num_iterations"
]]
-
1L
# pop interaction_constraints off of params. It needs some preprocessing on the
# R side before being passed into the Dataset object
interaction_constraints
<-
params
[[
"interaction_constraints"
]]
params
[
"interaction_constraints"
]
<-
NULL
# Construct datasets, if needed
data
$
update_params
(
params
=
params
)
data
$
construct
()
...
...
@@ -177,7 +182,10 @@ lgb.cv <- function(params = list()
}
else
if
(
!
is.null
(
data
$
get_colnames
()))
{
cnames
<-
data
$
get_colnames
()
}
params
[[
"interaction_constraints"
]]
<-
lgb.check_interaction_constraints
(
params
=
params
,
column_names
=
cnames
)
params
[[
"interaction_constraints"
]]
<-
lgb.check_interaction_constraints
(
interaction_constraints
=
interaction_constraints
,
column_names
=
cnames
)
# Check for weights
if
(
!
is.null
(
weight
))
{
...
...
R-package/R/lgb.train.R
View file @
fa6d3565
...
...
@@ -144,6 +144,11 @@ lgb.train <- function(params = list(),
}
end_iteration
<-
begin_iteration
+
params
[[
"num_iterations"
]]
-
1L
# pop interaction_constraints off of params. It needs some preprocessing on the
# R side before being passed into the Dataset object
interaction_constraints
<-
params
[[
"interaction_constraints"
]]
params
[
"interaction_constraints"
]
<-
NULL
# Construct datasets, if needed
data
$
update_params
(
params
=
params
)
data
$
construct
()
...
...
@@ -156,7 +161,7 @@ lgb.train <- function(params = list(),
cnames
<-
data
$
get_colnames
()
}
params
[[
"interaction_constraints"
]]
<-
lgb.check_interaction_constraints
(
params
=
param
s
interaction_constraints
=
interaction_constraint
s
,
column_names
=
cnames
)
...
...
R-package/R/utils.R
View file @
fa6d3565
...
...
@@ -168,21 +168,21 @@ lgb.params2str <- function(params, ...) {
}
lgb.check_interaction_constraints
<-
function
(
param
s
,
column_names
)
{
lgb.check_interaction_constraints
<-
function
(
interaction_constraint
s
,
column_names
)
{
# Convert interaction constraints to feature numbers
string_constraints
<-
list
()
if
(
!
is.null
(
params
[[
"
interaction_constraints
"
]]
))
{
if
(
!
is.null
(
interaction_constraints
))
{
if
(
!
methods
::
is
(
params
[[
"
interaction_constraints
"
]]
,
"list"
))
{
if
(
!
methods
::
is
(
interaction_constraints
,
"list"
))
{
stop
(
"interaction_constraints must be a list"
)
}
if
(
!
all
(
sapply
(
params
[[
"
interaction_constraints
"
]]
,
function
(
x
)
{
is.character
(
x
)
||
is.numeric
(
x
)})))
{
if
(
!
all
(
sapply
(
interaction_constraints
,
function
(
x
)
{
is.character
(
x
)
||
is.numeric
(
x
)})))
{
stop
(
"every element in interaction_constraints must be a character vector or numeric vector"
)
}
for
(
constraint
in
params
[[
"
interaction_constraints
"
]]
)
{
for
(
constraint
in
interaction_constraints
)
{
# Check for character name
if
(
is.character
(
constraint
))
{
...
...
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