Skip to content

Commit e8b17d5

Browse files
committed
prohibit use of regression_l1 objective with linear trees
1 parent 6437645 commit e8b17d5

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
args: ["--strict"]
2525
- repo: https://github.com/astral-sh/ruff-pre-commit
2626
# Ruff version.
27-
rev: v0.9.5
27+
rev: v0.9.10
2828
hooks:
2929
# Run the linter.
3030
- id: ruff
@@ -39,13 +39,13 @@ repos:
3939
hooks:
4040
- id: shellcheck
4141
- repo: https://github.com/crate-ci/typos
42-
rev: v1.29.5
42+
rev: v1.30.2
4343
hooks:
4444
- id: typos
4545
args: ["--force-exclude"]
4646
exclude: (\.gitignore$)|(^\.editorconfig$)
4747
- repo: https://github.com/henryiii/validate-pyproject-schema-store
48-
rev: 2025.02.03
48+
rev: 2025.03.10
4949
hooks:
5050
- id: validate-pyproject
5151
files: python-package/pyproject.toml$

src/io/config.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ void Config::CheckParamConflict(const std::unordered_map<std::string, std::strin
428428
if (zero_as_missing) {
429429
Log::Fatal("zero_as_missing must be false when fitting linear trees.");
430430
}
431-
if (objective == std::string("regresson_l1")) {
431+
if (objective == std::string("regression_l1")) {
432432
Log::Fatal("Cannot use regression_l1 objective when fitting linear trees.");
433433
}
434434
}

tests/python_package_test/test_engine.py

+16
Original file line numberDiff line numberDiff line change
@@ -3799,6 +3799,22 @@ def test_linear_single_leaf():
37993799
assert log_loss(y_train, y_pred) < 0.661
38003800

38013801

3802+
def test_linear_raises_informative_errors_on_unsupported_params():
3803+
X, y = make_synthetic_regression()
3804+
with pytest.raises(lgb.basic.LightGBMError, match="Cannot use regression_l1 objective when fitting linear trees"):
3805+
lgb.train(
3806+
train_set=lgb.Dataset(X, label=y),
3807+
params={"linear_tree": True, "objective": "regression_l1"},
3808+
num_boost_round=1,
3809+
)
3810+
with pytest.raises(lgb.basic.LightGBMError, match="zero_as_missing must be false when fitting linear trees"):
3811+
lgb.train(
3812+
train_set=lgb.Dataset(X, label=y),
3813+
params={"linear_tree": True, "zero_as_missing": True},
3814+
num_boost_round=1,
3815+
)
3816+
3817+
38023818
def test_predict_with_start_iteration():
38033819
def inner_test(X, y, params, early_stopping_rounds):
38043820
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42)

0 commit comments

Comments
 (0)