Skip to content

feat: 999 stacked area plot for ensemble model learned weights - #1124

Open
fleur-petit wants to merge 6 commits into
mainfrom
feature/999-stacked-area-plot-for-ensemble-model-contributions
Open

fleur-petit wants to merge 6 commits into
mainfrom
feature/999-stacked-area-plot-for-ensemble-model-contributions

Conversation

@fleur-petit

Copy link
Copy Markdown
Collaborator

Assisted-by: GitHub Copilot

What does this PR do?

Adds a ModelContributionsPlotter that allows users to plot learned model weights as stacked area plots. Can choose one quantile. Top panel shows the forecast.

output

Closes #999

Type of change

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

AI disclosure

  • No AI assistance was used (beyond grammar/spelling)
  • AI assistance was used — tool(s):
    • 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>)

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)

@fleur-petit
fleur-petit requested a review from a team October 2, 2026 08:36
@fleur-petit fleur-petit linked an issue Oct 2, 2026 that may be closed by this pull request
5 tasks
@github-actions github-actions Bot added the feature New feature or request label Oct 2, 2026
import pandas as pd


def make_two_panel_time_figure() -> go.Figure:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

is it okay to place those helpers here?

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.

I think it's fine to have a module with helpers for plotting. But I would not use '_' prefixed modules.

Mainly cause it hides it from the library users and makes importing it a bad pattern which linters will complain about. So if they want to extend the library they have to come up with their own helpers. So probably a better filename like layout.py or common.py may be better.

We should change add top line to something slightly less ambiguous by adidng more context.

Perhaps make the two helper methods classmethod on a class called something like 'VerticalSplitPlotLayout' or something that makes sense. Then it's clear that the two belong together.

row_heights=[0.2, 0.8],
vertical_spacing=0.03,
)
fig = make_two_panel_time_figure()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

reusing those helpers in the model contributions plotter

contributions: Per-model selection weights from a learned-weights
``EnsembleForecastingModel``. Use the result of
``predict_contributions()`` or the second element of
``predict_with_contributions()``. Columns contain model weights

@fleur-petit fleur-petit Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Limited to learned model weights, not for SHAP values, is that alright?

ensemble_dataset=ensemble_predictions,
original_data=data,
)
return forecast, contributions

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

added this so that I would have both the forecast and the contributions for the two model contributions plotter panels. Does it make sense to add this here? Or would another approach be better suited?

fig = ModelContributionsPlotter.plot_stacked_area(
model_weights,
forecast=ensemble_forecast,
quantile=Q(0.1),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Image

@egordm in the heatmap you showed me the contributions of models at different quantiles simulteneously. That is not what this figure does, it shows the learned model weights for one quantile. It cannot replace the heatmap, but is it a useful addition? Are there tweaks I can do to make it as useful to you as the heatmap?

@egordm egordm 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.

Overall looks great. Good work! Just some nitpicks around the plot helpers.

@fleur-petit
fleur-petit requested a review from egordm October 2, 2026 14:04
@fleur-petit
fleur-petit force-pushed the feature/999-stacked-area-plot-for-ensemble-model-contributions branch 5 times, most recently from 3d8863e to 6c3de42 Compare October 9, 2026 20:09
Signed-off-by: Fleur Petit <fleur.petit@alliander.com>
Signed-off-by: Fleur Petit <fleur.petit@alliander.com>
Signed-off-by: Fleur Petit <fleur.petit@alliander.com>
…are plotted.

Signed-off-by: Fleur Petit <fleur.petit@alliander.com>
…t to class.

Signed-off-by: Fleur Petit <fleur.petit@alliander.com>
Signed-off-by: Fleur Petit <fleur.petit@alliander.com>
@fleur-petit
fleur-petit force-pushed the feature/999-stacked-area-plot-for-ensemble-model-contributions branch from 6c3de42 to 5348f31 Compare October 9, 2026 20:17
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

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

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stacked-area plot for ensemble model contributions

2 participants