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”.
- 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"})
- frame(with_average_precision=False)[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.
- Returns:
- DataFrame
A DataFrame containing the precision-recall curve data with columns depending on the report type:
estimator_name
: Name of the estimator (when comparing estimators)split_index
: Cross-validation fold ID (when doing cross-validation)label
: Class label (for multiclass-classification)threshold
: Decision thresholdprecision
: Precision score at thresholdrecall
: Recall score at thresholdaverage_precision
: average precision (whenwith_average_precision=True
)
Examples
>>> from sklearn.datasets import load_breast_cancer >>> from sklearn.linear_model import LogisticRegression >>> from skore import train_test_split, 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) >>> clf = LogisticRegression(max_iter=10_000) >>> report = EstimatorReport(clf, **split_data) >>> display = report.metrics.precision_recall() >>> df = display.frame()
- 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.