GroupedTargetMetricPlotter#
- class openstef_beam.analysis.plots.grouped_target_metric_plotter.GroupedTargetMetricPlotter[source]
Bases:
objectCreates 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:
- 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.
- 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:
- 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