PrecisionRecallCurvePlotter#
- class openstef_beam.analysis.plots.PrecisionRecallCurvePlotter[source]
Bases:
objectCreates precision-recall curves for model performance across quantiles.
This plotter evaluates forecast performance at different probability thresholds by visualizing the trade-off between precision and recall for each model.
The plots help answer:
Which model provides the best precision-recall trade-off?
How does performance vary across different quantile thresholds?
What quantile levels achieve optimal model performance?
The resulting curves show:
Precision vs recall curves for each model
Interactive hover data showing quantile values
Comparative model performance visualization
Higher curves (closer to top-right) indicate better overall performance, while specific points help identify optimal operating thresholds.
Example
Comparing model performance across quantiles
>>> from openstef_core.types import Quantile >>> plotter = PrecisionRecallCurvePlotter() >>> >>> # Add model performance data >>> precision = [0.8, 0.75, 0.7, 0.65] >>> recall = [0.6, 0.7, 0.8, 0.85] >>> quantiles = [Quantile(0.1), Quantile(0.3), Quantile(0.5), Quantile(0.9)] >>> _ = plotter.add_model("XGBoost", precision, recall, quantiles) >>> # Generate precision-recall curve >>> fig = plotter.plot(title="Model Performance Analysis") >>> type(fig).__name__ 'Figure'
- __init__()[source]
Initialize the plotter with empty model data storage.
- add_model(model_name: str, precision_values: list[float], recall_values: list[float], quantiles: list[Quantile]) PrecisionRecallCurvePlotter[source]
Add a model’s precision and recall values to the plot.
- Parameters:
model_name (
str) – The name of the model.precision_values (
list[float]) – List of precision values for each quantile.recall_values (
list[float]) – List of recall values for each quantile.quantiles (
list[Quantile]) – List of quantile values. If None, will use indices.model_name
precision_values
recall_values
quantiles
- Returns:
The current instance for method chaining.
- Return type:
PrecisionRecallCurvePlotter
- Raises:
ValueError – If precision and recall lists have different lengths, or if quantiles list has different length than precision/recall lists.
- Return type:
PrecisionRecallCurvePlotter
- plot(title: str = 'Precision-Recall Curve') Figure[source]
Create and return a precision-recall curve plot for all added models.
- Parameters:
title (
str) – Title of the plot.title
- Returns:
The precision-recall curve plot.
- Return type:
plotly.graph_objects.Figure
- Raises:
ValueError – If no model data has been added.
- Return type:
Figure