PrecisionRecallCurveDisplay#
- class skore.PrecisionRecallCurveDisplay(*, precision_recall, average_precision, pos_label, data_source, ml_task, report_type)[source]#
Precision Recall visualization.
An instance of this class is should 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_name” - “split_index” (may be null) - “label” - “threshold” - “precision” - “recall”.
- average_precisionDataFrame
The average precision data to display. The columns are - “estimator_name” - “split_index” (may be null) - “label” - “average_precision”.
- estimator_nameslist of str
Name of the estimators.
- pos_labelint, float, bool, str or None
The class considered as the positive class. If None, the class will not be shown in the legend.
- data_source{“train”, “test”, “X_y”}
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.
- Attributes:
- ax_matplotlib axes or ndarray of axes
The axes on which the precision-recall curve is plotted.
- figure_matplotlib figure
The figure on which the precision-recall curve is plotted.
- lines_list of matplotlib lines
The lines of the precision-recall curve.
Examples
>>> from sklearn.datasets import load_breast_cancer >>> from sklearn.linear_model import LogisticRegression >>> from skore import train_test_split >>> from skore import EstimatorReport >>> X, y = load_breast_cancer(return_X_y=True) >>> split_data = train_test_split(X=X, y=y, random_state=0, as_dict=True) >>> classifier = LogisticRegression(max_iter=10_000) >>> report = EstimatorReport(classifier, **split_data) >>> display = report.metrics.precision_recall() >>> display.plot(pr_curve_kwargs={"color": "tab:red"})
- plot(*, estimator_name=None, pr_curve_kwargs=None, despine=True)[source]#
Plot visualization.
Extra keyword arguments will be passed to matplotlib’s
plot
.- Parameters:
- estimator_namestr, default=None
Name of the estimator used to plot the precision-recall curve. If
None
, we use the inferred name from the estimator.- pr_curve_kwargsdict or list of dict, default=None
Keyword arguments to be passed to matplotlib’s
plot
for rendering the precision-recall curve(s).- despinebool, default=True
Whether to remove the top and right spines from the plot.
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).You can change this style by passing the keyword argument
drawstyle="default"
. However, the curve will not be strictly consistent with the reported average precision.Examples
>>> from sklearn.datasets import load_breast_cancer >>> from sklearn.linear_model import LogisticRegression >>> from skore import train_test_split >>> from skore import EstimatorReport >>> X, y = load_breast_cancer(return_X_y=True) >>> split_data = train_test_split(X=X, y=y, random_state=0, as_dict=True) >>> classifier = LogisticRegression(max_iter=10_000) >>> report = EstimatorReport(classifier, **split_data) >>> display = report.metrics.precision_recall() >>> display.plot(pr_curve_kwargs={"color": "tab:red"})
- set_style(**kwargs)[source]#
Set the style parameters for the display.
- Parameters:
- **kwargsdict
Style parameters to set. Each parameter name should correspond to a a style attribute passed to the plot method of the display.
- Returns:
- selfobject
Returns the instance itself.
- Raises:
- ValueError
If a style parameter is unknown.