Skip to content

Commit 46a406e

Browse files
Copilotthinkall
andauthored
Add objective parameter to LGBMEstimator search space (#1474)
* Initial plan * Add objective parameter to LGBMEstimator search_space Co-authored-by: thinkall <3197038+thinkall@users.noreply.github.com> * Add test for LGBMEstimator objective parameter Co-authored-by: thinkall <3197038+thinkall@users.noreply.github.com> * Fix format error * Remove changes, just add a test to verify the current supported usage --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: thinkall <3197038+thinkall@users.noreply.github.com> Co-authored-by: Li Jiang <bnujli@gmail.com> Co-authored-by: Li Jiang <lijiang1@microsoft.com>
1 parent f1817ea commit 46a406e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/automl/test_custom_hp.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,39 @@ def test_custom_hp():
7272
print(automl.best_config_per_estimator)
7373

7474

75+
def test_lgbm_objective():
76+
"""Test that objective parameter can be set via custom_hp for LGBMEstimator"""
77+
import numpy as np
78+
79+
# Create a simple regression dataset
80+
np.random.seed(42)
81+
X_train = np.random.rand(100, 5)
82+
y_train = np.random.rand(100) * 100 # Scale to avoid division issues with MAPE
83+
84+
automl = AutoML()
85+
settings = {
86+
"time_budget": 3,
87+
"metric": "mape",
88+
"task": "regression",
89+
"estimator_list": ["lgbm"],
90+
"verbose": 0,
91+
"custom_hp": {"lgbm": {"objective": {"domain": "mape"}}}, # Fixed value, not tuned
92+
}
93+
94+
automl.fit(X_train, y_train, **settings)
95+
96+
# Verify that objective was set correctly
97+
assert "objective" in automl.best_config, "objective should be in best_config"
98+
assert automl.best_config["objective"] == "mape", "objective should be 'mape'"
99+
100+
# Verify the model has the correct objective
101+
if hasattr(automl.model, "estimator") and hasattr(automl.model.estimator, "get_params"):
102+
model_params = automl.model.estimator.get_params()
103+
assert model_params.get("objective") == "mape", "Model should use 'mape' objective"
104+
105+
print("Test passed: objective parameter works correctly with LGBMEstimator")
106+
107+
75108
if __name__ == "__main__":
76109
test_custom_hp()
110+
test_lgbm_objective()

0 commit comments

Comments
 (0)