WindowedMetricPlotter#
- class openstef_beam.analysis.plots.windowed_metric_plotter.WindowedMetricPlotter[source]
Bases:
objectCreates time series plots of performance metrics using windowed analysis.
This plotter visualizes how model performance changes over time by computing metrics within rolling time windows. This helps identify temporal patterns, seasonal variations, and long-term trends in forecast accuracy.
The plots show:
Performance metrics over time for each model
Rolling averages to smooth out short-term fluctuations
Comparative analysis across multiple models
Trend identification for performance monitoring
Example
Basic usage for RMSE over time
>>> from datetime import datetime >>> plotter = WindowedMetricPlotter() >>> timestamps = [datetime(2024, 1, 1), datetime(2024, 1, 2)] >>> rmse_values = [0.12, 0.15] >>> _ = plotter.add_model("XGBoost", timestamps, rmse_values) >>> _ = plotter.set_window_size("1D") >>> fig = plotter.plot(title="RMSE Over Time", metric_name="RMSE") >>> type(fig).__name__ 'Figure'
- __init__()[source]
Initialize the plotter with empty data containers.
- add_model(model_name: str, timestamps: list[datetime], metric_values: list[float]) WindowedMetricPlotter[source]
Add a model’s metric values and timestamps to the plot.
- Parameters:
- Returns:
The current instance for method chaining.
- Return type:
WindowedMetricPlotter
- Raises:
ValueError – If timestamps and metric values have different lengths.
- Return type:
WindowedMetricPlotter
- set_window_size(window_size: str) WindowedMetricPlotter[source]
Set the window size used for metric calculation.
- Parameters:
window_size (
str) – Description of the window size (e.g., “7 days”).window_size
- Returns:
The current instance for method chaining.
- Return type:
WindowedMetricPlotter
- Return type:
WindowedMetricPlotter
- plot(title: str = 'Metric over time', metric_name: str = 'Metric') Figure[source]
Create and return a line chart of metrics over time for all added models.
- Parameters:
- Returns:
The resulting plot.
- Return type:
plotly.graph_objects.Figure
- Raises:
ValueError – If no model data has been added.
- Return type:
Figure