fix: exclude exponential loss for GradientBoostingClassifier on multiclass targets#120
Open
fix: exclude exponential loss for GradientBoostingClassifier on multiclass targets#120
Conversation
…class targets (#64) sklearn's ExponentialLoss only supports binary classification. When hyperparameter tuning was enabled with GradientBoostingClassifier on a multiclass target, optuna would occasionally sample loss='exponential', triggering "ExponentialLoss requires 2 classes". Changes: - hyperparameters.py.jinja: gate 'exponential' behind is_multiclass check; also drop the long-removed 'deviance' alias (removed in sklearn 1.3) - pipeline_template.py: forward pipeline.task.is_multiclass into the hyperparameters template render context - test_hyperparameters_template.py: add four regression tests covering multiclass/binary template rendering and an end-to-end optuna study on a 3-class synthetic dataset Co-authored-by: openhands <openhands@all-hands.dev> Signed-off-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev> Signed-off-by: openhands <openhands@all-hands.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #64.
sklearn’s
ExponentialLossonly supports binary classification. When hyperparameter tuning was enabled withGradientBoostingClassifieron a multiclass target, optuna would occasionally sampleloss='exponential', raising:The same bug also listed
'deviance'as a loss candidate — that alias was removed in sklearn 1.3 and would raiseValueErroron any modern install.Changes
sapientml_core/templates/model_templates/hyperparameters.py.jinja'exponential'behind{% if not is_multiclass %}— binary-only, never emitted for multiclass targets.'deviance'entirely (removed in sklearn 1.3).sapientml_core/adaptation/generation/pipeline_template.pypipeline.task.is_multiclassinto the hyperparameters template render context so the Jinja guard has the information it needs.tests/sapientml/test_hyperparameters_template.py_renderhelper to accept an optionalis_multiclassparameter (defaultFalse, preserving all existing tests).test_gradient_boosting_classifier_multiclass_excludes_exponential— verifies'exponential'never appears whenis_multiclass=True.test_gradient_boosting_classifier_binary_includes_exponential— verifies'exponential'is available for binary classification.test_gradient_boosting_classifier_always_excludes_deviance— verifies'deviance'never appears in any rendering.test_gradient_boosting_multiclass_tuning_completes_without_error— end-to-end optuna study on a synthetic 3-class dataset that must complete all trials withoutValueError.Test results
All 38 tests pass (
pytest tests/sapientml/test_hyperparameters_template.py).