From 46a406edd46e3dd15f7c5bc52e57b13bbfc442ca Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Jan 2026 21:10:21 +0800 Subject: [PATCH] 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 Co-authored-by: Li Jiang --- test/automl/test_custom_hp.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/automl/test_custom_hp.py b/test/automl/test_custom_hp.py index b06ae9f2c..fe846071f 100644 --- a/test/automl/test_custom_hp.py +++ b/test/automl/test_custom_hp.py @@ -72,5 +72,39 @@ def test_custom_hp(): print(automl.best_config_per_estimator) +def test_lgbm_objective(): + """Test that objective parameter can be set via custom_hp for LGBMEstimator""" + import numpy as np + + # Create a simple regression dataset + np.random.seed(42) + X_train = np.random.rand(100, 5) + y_train = np.random.rand(100) * 100 # Scale to avoid division issues with MAPE + + automl = AutoML() + settings = { + "time_budget": 3, + "metric": "mape", + "task": "regression", + "estimator_list": ["lgbm"], + "verbose": 0, + "custom_hp": {"lgbm": {"objective": {"domain": "mape"}}}, # Fixed value, not tuned + } + + automl.fit(X_train, y_train, **settings) + + # Verify that objective was set correctly + assert "objective" in automl.best_config, "objective should be in best_config" + assert automl.best_config["objective"] == "mape", "objective should be 'mape'" + + # Verify the model has the correct objective + if hasattr(automl.model, "estimator") and hasattr(automl.model.estimator, "get_params"): + model_params = automl.model.estimator.get_params() + assert model_params.get("objective") == "mape", "Model should use 'mape' objective" + + print("Test passed: objective parameter works correctly with LGBMEstimator") + + if __name__ == "__main__": test_custom_hp() + test_lgbm_objective()