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
18c11f86
Unverified
Commit
18c11f86
authored
Apr 17, 2025
by
James Lamb
Committed by
GitHub
Apr 17, 2025
Browse files
prohibit use of regression_l1 objective with linear trees (#6859)
parent
d18fff10
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
4 deletions
+20
-4
.pre-commit-config.yaml
.pre-commit-config.yaml
+3
-3
src/io/config.cpp
src/io/config.cpp
+1
-1
tests/python_package_test/test_engine.py
tests/python_package_test/test_engine.py
+16
-0
No files found.
.pre-commit-config.yaml
View file @
18c11f86
...
@@ -24,7 +24,7 @@ repos:
...
@@ -24,7 +24,7 @@ repos:
args
:
[
"
--strict"
]
args
:
[
"
--strict"
]
-
repo
:
https://github.com/astral-sh/ruff-pre-commit
-
repo
:
https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
# Ruff version.
rev
:
v0.9.
5
rev
:
v0.9.
10
hooks
:
hooks
:
# Run the linter.
# Run the linter.
-
id
:
ruff
-
id
:
ruff
...
@@ -39,13 +39,13 @@ repos:
...
@@ -39,13 +39,13 @@ repos:
hooks
:
hooks
:
-
id
:
shellcheck
-
id
:
shellcheck
-
repo
:
https://github.com/crate-ci/typos
-
repo
:
https://github.com/crate-ci/typos
rev
:
v1.
29.5
rev
:
v1.
30.2
hooks
:
hooks
:
-
id
:
typos
-
id
:
typos
args
:
[
"
--force-exclude"
]
args
:
[
"
--force-exclude"
]
exclude
:
(\.gitignore$)|(^\.editorconfig$)
exclude
:
(\.gitignore$)|(^\.editorconfig$)
-
repo
:
https://github.com/henryiii/validate-pyproject-schema-store
-
repo
:
https://github.com/henryiii/validate-pyproject-schema-store
rev
:
2025.0
2.03
rev
:
2025.0
3.10
hooks
:
hooks
:
-
id
:
validate-pyproject
-
id
:
validate-pyproject
files
:
python-package/pyproject.toml$
files
:
python-package/pyproject.toml$
src/io/config.cpp
View file @
18c11f86
...
@@ -428,7 +428,7 @@ void Config::CheckParamConflict(const std::unordered_map<std::string, std::strin
...
@@ -428,7 +428,7 @@ void Config::CheckParamConflict(const std::unordered_map<std::string, std::strin
if
(
zero_as_missing
)
{
if
(
zero_as_missing
)
{
Log
::
Fatal
(
"zero_as_missing must be false when fitting linear trees."
);
Log
::
Fatal
(
"zero_as_missing must be false when fitting linear trees."
);
}
}
if
(
objective
==
std
::
string
(
"regresson_l1"
))
{
if
(
objective
==
std
::
string
(
"regress
i
on_l1"
))
{
Log
::
Fatal
(
"Cannot use regression_l1 objective when fitting linear trees."
);
Log
::
Fatal
(
"Cannot use regression_l1 objective when fitting linear trees."
);
}
}
}
}
...
...
tests/python_package_test/test_engine.py
View file @
18c11f86
...
@@ -3799,6 +3799,22 @@ def test_linear_single_leaf():
...
@@ -3799,6 +3799,22 @@ def test_linear_single_leaf():
assert
log_loss
(
y_train
,
y_pred
)
<
0.661
assert
log_loss
(
y_train
,
y_pred
)
<
0.661
def
test_linear_raises_informative_errors_on_unsupported_params
():
X
,
y
=
make_synthetic_regression
()
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
,
match
=
"Cannot use regression_l1 objective when fitting linear trees"
):
lgb
.
train
(
train_set
=
lgb
.
Dataset
(
X
,
label
=
y
),
params
=
{
"linear_tree"
:
True
,
"objective"
:
"regression_l1"
},
num_boost_round
=
1
,
)
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
,
match
=
"zero_as_missing must be false when fitting linear trees"
):
lgb
.
train
(
train_set
=
lgb
.
Dataset
(
X
,
label
=
y
),
params
=
{
"linear_tree"
:
True
,
"zero_as_missing"
:
True
},
num_boost_round
=
1
,
)
def
test_predict_with_start_iteration
():
def
test_predict_with_start_iteration
():
def
inner_test
(
X
,
y
,
params
,
early_stopping_rounds
):
def
inner_test
(
X
,
y
,
params
,
early_stopping_rounds
):
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.1
,
random_state
=
42
)
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.1
,
random_state
=
42
)
...
...
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