Unverified Commit 18c11f86 authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

prohibit use of regression_l1 objective with linear trees (#6859)

parent d18fff10
......@@ -24,7 +24,7 @@ repos:
args: ["--strict"]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.5
rev: v0.9.10
hooks:
# Run the linter.
- id: ruff
......@@ -39,13 +39,13 @@ repos:
hooks:
- id: shellcheck
- repo: https://github.com/crate-ci/typos
rev: v1.29.5
rev: v1.30.2
hooks:
- id: typos
args: ["--force-exclude"]
exclude: (\.gitignore$)|(^\.editorconfig$)
- repo: https://github.com/henryiii/validate-pyproject-schema-store
rev: 2025.02.03
rev: 2025.03.10
hooks:
- id: validate-pyproject
files: python-package/pyproject.toml$
......@@ -428,7 +428,7 @@ void Config::CheckParamConflict(const std::unordered_map<std::string, std::strin
if (zero_as_missing) {
Log::Fatal("zero_as_missing must be false when fitting linear trees.");
}
if (objective == std::string("regresson_l1")) {
if (objective == std::string("regression_l1")) {
Log::Fatal("Cannot use regression_l1 objective when fitting linear trees.");
}
}
......
......@@ -3799,6 +3799,22 @@ def test_linear_single_leaf():
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 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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment