Derive seasonal lags from sensor resolution#2157
Open
BelhsanHmida wants to merge 5 commits into
Open
Conversation
Context: - Forecasting daily seasonality was hard-coded to 24 lag steps. - That only represents one day for hourly sensors. Change: - Add a seasonal_lag_steps parameter to CustomLGBM. - Keep the previous 24-step default for compatibility. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Daily lag steps depend on the target sensor resolution. - PT15M sensors need 96 steps to represent one day, not 24. Change: - Compute one-day lag steps from the target sensor event resolution. - Pass the derived value into CustomLGBM during training. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Resolution-aware daily lags need enough training samples for the full requested horizon. - Three days of PT15M data with a 48h horizon used to produce forecasts on main and should not become a hard failure. Change: - Fall back to the legacy 24-step lag pattern when the training window cannot support daily lags for the farthest horizon. - Add regression coverage for under-sampled and sufficiently sampled PT15M histories. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the LightGBM forecasting model so daily seasonal lag features can scale with the target sensor resolution, improving support for sub-hourly forecasting.
Changes:
- Adds configurable seasonal lag parameters to
CustomLGBM. - Derives daily lag steps from
target_sensor.event_resolutionduring training. - Adds a unit test for fallback behavior when history is too short for the requested daily lag.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
flexmeasures/data/models/forecasting/custom_models/lgbm_model.py |
Adds seasonal lag configuration and fallback logic. |
flexmeasures/data/models/forecasting/pipelines/train.py |
Passes derived daily lag steps and training sample count into CustomLGBM. |
flexmeasures/data/tests/test_forecasting_pipeline.py |
Tests fallback vs daily seasonal lag selection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+129
to
+131
| seasonal_lag_steps=max( | ||
| int(timedelta(days=1) / self.target_sensor.event_resolution), 1 | ||
| ), |
Comment on lines
+33
to
+36
| seasonal_lag_steps=24, | ||
| fallback_lag_steps=24, | ||
| training_sample_count=None, | ||
| min_samples_per_horizon=2, |
| lag = ( | ||
| 24 | ||
| self.seasonal_lag_steps | ||
| - ( # temporarily make the adaptation to the sensor resolution; To do: inlude a list of seasonal lags to include, given as pd.timedelta objects |
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.
Description
Look & Feel
N/A
How to test
Further Improvements
Related Items
Sign-off