PrecisionRecallCurveDisplay#

class skore.PrecisionRecallCurveDisplay(*, precision_recall, average_precision, report_pos_label, data_source, ml_task, report_type)[source]#

Precision Recall visualization.

An instance of this class should be created by EstimatorReport.metrics.precision_recall(). You should not create an instance of this class directly.

Parameters:
precision_recallDataFrame

The precision-recall curve data to display. The columns are

  • estimator

  • split (may be null)

  • label

  • threshold

  • precision

  • recall

  • data_source.

average_precisionDataFrame

The average precision data to display. The columns are

  • estimator

  • split (may be null)

  • label

  • average_precision.

report_pos_labelint, float, bool, str or None

Default positive label used when plot(label=...) is not specified.

data_source{“train”, “test”, “both”}

The data source used to compute the precision recall curve.

ml_task{“binary-classification”, “multiclass-classification”}

The machine learning task.

report_type{“comparison-cross-validation”, “comparison-estimator”, “cross-validation”, “estimator”}

The type of report.

Examples

>>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.linear_model import LogisticRegression
>>> from skore import evaluate
>>> X, y = load_breast_cancer(return_X_y=True)
>>> classifier = LogisticRegression(max_iter=10_000)
>>> report = evaluate(classifier, X, y, splitter=0.2)
>>> display = report.metrics.precision_recall()
>>> display.set_style(relplot_kwargs={"palette": "Set2"})
>>> display.plot()
frame(with_average_precision=False, label=<DEFAULT>)[source]#

Get the data used to create the precision-recall curve plot.

Parameters:
with_average_precisionbool, default=False

Whether to include the average precision column in the returned DataFrame.

labelint, float, bool, str or None, default=report pos_label

The class whose curve to select. We always compute one curve per class, in a one-vs-rest fashion in multiclass classification and by alternating the positive class in binary classification. This lets you display only the curve of the desired class. Use None to show them all.

Returns:
DataFrame

A DataFrame containing the precision-recall curve data with columns depending on the report type:

  • estimator: Name of the estimator (when comparing estimators)

  • split: Cross-validation split ID (when doing cross-validation)

  • label: Class label (when plotting one-vs-rest curves)

  • threshold: Decision threshold

  • precision: Precision score at threshold

  • recall: Recall score at threshold

  • data_source: Data source used (when data_source="both")

  • average_precision: average precision (when with_average_precision=True)

Examples

>>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.linear_model import LogisticRegression
>>> from skore import evaluate
>>> X, y = load_breast_cancer(return_X_y=True)
>>> clf = LogisticRegression(max_iter=10_000)
>>> report = evaluate(clf, X, y, splitter=0.2)
>>> display = report.metrics.precision_recall()
>>> df = display.frame()
help()[source]#

Display display help using rich or HTML.

plot(*, subplot_by='auto', despine=True, label=<DEFAULT>)[source]#

Plot visualization.

Parameters:
subplot_by{“auto”, “label”, “estimator”, “data_source”} or None, default=”auto”

Column to use for creating subplots. Options:

  • “auto”: None for EstimatorReport and Cross-Validation Report, “estimator” for ComparisonReport

  • “label”: one subplot per class when plotting one-vs-rest curves

  • “estimator”: one subplot per estimator (comparison only)

  • “data_source”: one subplot per data source (EstimatorReport with both data sources only)

  • None: no subplots (Not available for comparison in classification with no specified label)

despinebool, default=True

Whether to remove the top and right spines from the plot.

labelint, float, bool, str or None, default=report pos_label

The class whose curve to select. We always compute one curve per class, in a one-vs-rest fashion in multiclass classification and by alternating the positive class in binary classification. This lets you display only the curve of the desired class. Use None to show them all.

Returns:
matplotlib.figure.Figure

Figure containing the precision-recall curve.

Notes

The average precision (cf. average_precision_score()) in scikit-learn is computed without any interpolation. To be consistent with this metric, the precision-recall curve is plotted without any interpolation as well (step-wise style).

Examples

>>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.linear_model import LogisticRegression
>>> from skore import evaluate
>>> X, y = load_breast_cancer(return_X_y=True)
>>> classifier = LogisticRegression(max_iter=10_000)
>>> report = evaluate(classifier, X, y, splitter=0.2)
>>> display = report.metrics.precision_recall()
>>> display.set_style(relplot_kwargs={"palette": "Set2", "alpha": 0.8})
>>> display.plot()
set_style(*, policy='update', relplot_kwargs=None)[source]#

Set the style parameters for the display.

Parameters:
policy{“override”, “update”}, default=”update”

Policy to use when setting the style parameters. If “override”, existing settings are set to the provided values. If “update”, existing settings are not changed; only settings that were previously unset are changed.

relplot_kwargsdict, default=None

Keyword arguments to be passed to seaborn.relplot() for rendering the precision-recall curve(s). Common options include palette, alpha, linewidth, etc.

Returns:
None
Raises:
ValueError

If a style parameter is unknown.

static style_plot(plot_func)[source]#

Apply consistent style to skore displays.

This decorator: 1. Applies default style settings 2. Runs plot_func under plt.ioff() so figures are not shown until returned 3. Calls Figure.tight_layout() on the returned figure when applicable 4. Restores the original style settings

Parameters:
plot_funccallable

The plot function to be decorated.

Returns:
callable

The decorated plot function.