Skip to content

feat: expose LightGBM importance type - #1177

Open
divya234-hue wants to merge 1 commit into
OpenSTEF:mainfrom
divya234-hue:divya234-hue-openstef-contribution-review
Open

divya234-hue wants to merge 1 commit into
OpenSTEF:mainfrom
divya234-hue:divya234-hue-openstef-contribution-review

Conversation

@divya234-hue

Copy link
Copy Markdown

What does this PR do?

LightGBM feature importance is currently calculated using its default split method, with no way to choose the alternative gain method through OpenSTEF. This adds a typed importance_type option to LGBMHyperParams, keeps the existing split default, and passes the selected value to each quantile estimator. Supported options are split and gain.

Closes #1170

Type of change

  • Bug fix
  • New feature
  • Breaking change (see checklist below)
  • Documentation
  • Refactor / chore / CI

Breaking changes checklist

  • Public API, config schema, or serialized/pickled objects changed in a way that affects existing users
  • If yes: see the breaking changes guide for the pickle/_migrate_state migration pattern

Migration path for existing users (e.g. "old pickled XScaler objects auto-migrate on load", "users must now pass X explicitly"):

N/A. The new configuration field is additive and defaults to LightGBM's existing split behavior.

AI disclosure

  • No AI assistance was used (beyond grammar/spelling)
  • AI assistance was used — tool(s): GitHub Copilot
    • I have reviewed, understand, and can explain all AI-generated code in this PR
    • This is disclosed in a commit message (e.g. Assisted-by: <tool name>)

AI assistance is disclosed here. The current commit does not include an Assisted-by trailer; the code and tests were validated as listed below.

Checklist

  • poe all --check passes locally
  • Tests added/updated for the change
  • Documentation updated (docstrings, user guide, examples) if needed
  • Commits are signed off per our DCO (git commit -s)
  • PR title follows Conventional Commits (e.g. feat: ..., fix: ..., feat!: ... for breaking changes)

Targeted checks passed:

  • uv run pytest packages\openstef-models\tests\unit\models\forecasting\test_lgbm_forecaster.py -q (9 passed)
  • uv run ruff check packages\openstef-models\src\openstef_models\models\forecasting\lgbm_forecaster.py packages\openstef-models\tests\unit\models\forecasting\test_lgbm_forecaster.py (passed)
  • uv run ruff format --check packages\openstef-models\src\openstef_models\models\forecasting\lgbm_forecaster.py packages\openstef-models\tests\unit\models\forecasting\test_lgbm_forecaster.py (passed)
  • uv run ty check packages\openstef-models\src\openstef_models\models\forecasting\lgbm_forecaster.py packages\openstef-models\tests\unit\models\forecasting\test_lgbm_forecaster.py (passed)
  • git diff --check (passed)

The full poe all --check suite was not run. The current commit is not DCO-signed-off.

@divya234-hue
divya234-hue requested a review from a team November 2, 2026 16:10
@divya234-hue

Copy link
Copy Markdown
Author

Hi! Could a maintainer please approve the workflows so the checks can run? Thanks!

@divya234-hue divya234-hue left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please look

@bartpleiter bartpleiter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! The changes look great and are approved, only a minor styling inconsistency with the tests that I would like to see fixed before we merge it.

Comment on lines +43 to +57
def test_lgbm_forecaster__importance_type_is_passed_to_models(importance_type: Literal["split", "gain"]) -> None:
forecaster = LGBMForecaster(
quantiles=[Q(0.1), Q(0.5), Q(0.9)],
horizons=[LeadTime(timedelta(days=1))],
hyperparams=LGBMHyperParams(importance_type=importance_type),
)

assert all(model.get_params()["importance_type"] == importance_type for model in forecaster._lgbm_model.models)


def test_lgbm_forecaster__importance_type_defaults_to_split(base_config: LGBMForecaster) -> None:
assert base_config.hyperparams.importance_type == "split"
assert all(model.get_params()["importance_type"] == "split" for model in base_config._lgbm_model.models)


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests look good, but as a minor nitpick it would be great if you could add the arrange act assert comments like in the other tests for consistency.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Add support for LightGBM importance_type hyperparameter

2 participants