GroupedTargetMetricPlotter#

class openstef_beam.analysis.plots.GroupedTargetMetricPlotter[source]

Bases: object

Creates bar charts and box plots comparing model metrics across multiple targets.

This plotter visualizes how different models perform across various forecasting targets, making it easy to identify which models work best for specific targets or target groups. The resulting charts help answer questions like:

  • Which model has the lowest error for residential vs commercial targets?

  • How consistent is model performance across similar target types?

  • Are there target-specific patterns in model accuracy?

The plotter can create either grouped bar charts (when no target groups are defined) or box plots (when targets are grouped by type/category), providing flexibility for different analysis needs.

Example

Basic usage comparing RMSE across targets

>>> plotter = GroupedTargetMetricPlotter()
>>> _ = plotter.add_model("XGBoost",
...                       targets=["target_A", "target_B", "target_C"],
...                       metric_values=[0.12, 0.15, 0.18])
>>> _ = plotter.add_model("Random Forest",
...                       targets=["target_A", "target_B", "target_C"],
...                       metric_values=[0.14, 0.13, 0.20])
>>> fig = plotter.plot(title="RMSE by Target", metric_name="RMSE")
>>> type(fig).__name__
'Figure'

With target grouping

>>> plotter2 = GroupedTargetMetricPlotter()
>>> _ = plotter2.add_model("XGBoost",
...                        targets=["target_A", "target_B"],
...                        metric_values=[0.12, 0.15])
>>> _ = plotter2.set_target_groups({"target_A": "Residential",
...                                 "target_B": "Commercial"})
>>> fig2 = plotter2.plot(title="RMSE by Target Group", metric_name="RMSE")
>>> type(fig2).__name__
'Figure'
__init__()[source]

Initialize the plotter with empty data containers.

add_model(model_name: str, targets: list[str], metric_values: list[float]) GroupedTargetMetricPlotter[source]

Add a model’s metric values for different targets to the plot.

Parameters:
  • model_name (str) – The name of the model.

  • targets (list[str]) – List of target names for the x-axis.

  • metric_values (list[float]) – List of metric values for the y-axis.

  • model_name

  • targets

  • metric_values

Returns:

The current instance for method chaining.

Return type:

GroupedTargetMetricPlotter

Raises:

ValueError – If targets and metric_values have different lengths.

Return type:

GroupedTargetMetricPlotter

set_target_groups(target_to_group_map: dict[str, str]) GroupedTargetMetricPlotter[source]

Set the mapping from targets to target groups.

Parameters:
  • target_to_group_map (dict[str, str]) – Dictionary mapping target names to their group names.

  • target_to_group_map

Returns:

The current instance for method chaining.

Return type:

GroupedTargetMetricPlotter

Return type:

GroupedTargetMetricPlotter

plot(title: str = 'Metric by Target', metric_name: str = 'Metric') Figure[source]

Create and return a plot of metrics across targets for all added models.

If target_groups is set, creates boxplots grouped by target groups. Otherwise creates a grouped bar chart with individual targets.

Parameters:
  • title (str) – Main title of the plot.

  • metric_name (str) – Name of the metric being plotted.

  • title

  • metric_name

Returns:

The resulting plot.

Return type:

plotly.graph_objects.Figure

Raises:

ValueError – If no model data has been added or if models contain targets that are not in the target groups mapping.

Return type:

Figure