Skip to content

Commit c62edd0

Browse files
committed
DOC: Improve terminology clarity in display classes
Replace ambiguous "chance level" terminology with clearer descriptions: - ROC curves: use "random classifier baseline" - PR curves: use "prevalence baseline" - Improves user understanding of reference lines Closes #30352
1 parent 59c4b7a commit c62edd0

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

sklearn/metrics/_plot/precision_recall_curve.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class PrecisionRecallDisplay(_BinaryClassifierCurveDisplayMixin):
4747
.. versionadded:: 0.24
4848
4949
prevalence_pos_label : float, default=None
50-
The prevalence of the positive label. It is used for plotting the
51-
chance level line. If None, the chance level line will not be plotted
50+
The prevalence of the positive label. It is used for plotting the
51+
prevalence baseline line (horizontal line representing the proportion
52+
of positive samples). If None, the baseline line will not be plotted
5253
even if `plot_chance_level` is set to True when plotting.
5354
5455
.. versionadded:: 1.3
@@ -58,8 +59,10 @@ class PrecisionRecallDisplay(_BinaryClassifierCurveDisplayMixin):
5859
line_ : matplotlib Artist
5960
Precision recall curve.
6061
61-
chance_level_ : matplotlib Artist or None
62-
The chance level line. It is `None` if the chance level is not plotted.
62+
chance_level : matplotlib Artist or None
63+
The prevalence baseline line (horizontal line representing the proportion
64+
of positive samples). It is `None` if the baseline is not plotted.
65+
6366
6467
.. versionadded:: 1.3
6568
@@ -154,15 +157,18 @@ def plot(
154157
`estimator_name` if not `None`, otherwise no labeling is shown.
155158
156159
plot_chance_level : bool, default=False
157-
Whether to plot the chance level. The chance level is the prevalence
158-
of the positive label computed from the data passed during
160+
Whether to plot the prevalence baseline. The baseline is the prevalence
161+
of the positive label computed from the data passed during
159162
:meth:`from_estimator` or :meth:`from_predictions` call.
160163
164+
161165
.. versionadded:: 1.3
162166
163167
chance_level_kw : dict, default=None
164-
Keyword arguments to be passed to matplotlib's `plot` for rendering
165-
the chance level line.
168+
Keyword arguments to be passed to matplotlib's `plot` for rendering
169+
the prevalence baseline line (horizontal line representing the
170+
proportion of positive samples).
171+
166172
167173
.. versionadded:: 1.3
168174
@@ -224,8 +230,8 @@ def plot(
224230
if self.prevalence_pos_label is None:
225231
raise ValueError(
226232
"You must provide prevalence_pos_label when constructing the "
227-
"PrecisionRecallDisplay object in order to plot the chance "
228-
"level line. Alternatively, you may use "
233+
"PrecisionRecallDisplay object in order to plot the prevalence "
234+
"baseline line. Alternatively, you may use "
229235
"PrecisionRecallDisplay.from_estimator or "
230236
"PrecisionRecallDisplay.from_predictions "
231237
"to automatically set prevalence_pos_label"
@@ -326,15 +332,18 @@ def from_estimator(
326332
Axes object to plot on. If `None`, a new figure and axes is created.
327333
328334
plot_chance_level : bool, default=False
329-
Whether to plot the chance level. The chance level is the prevalence
330-
of the positive label computed from the data passed during
331-
:meth:`from_estimator` or :meth:`from_predictions` call.
335+
Whether to plot the prevalence baseline (horizontal reference line).
336+
The baseline represents the prevalence of the positive label computed
337+
from the data passed during :meth:`from_estimator` or
338+
:meth:`from_predictions` call.
332339
333340
.. versionadded:: 1.3
334341
335342
chance_level_kw : dict, default=None
336-
Keyword arguments to be passed to matplotlib's `plot` for rendering
337-
the chance level line.
343+
Keyword arguments to be passed to matplotlib's `plot` for rendering
344+
the prevalence baseline line (horizontal line representing the
345+
proportion of positive samples).
346+
338347
339348
.. versionadded:: 1.3
340349
@@ -466,15 +475,19 @@ def from_predictions(
466475
Axes object to plot on. If `None`, a new figure and axes is created.
467476
468477
plot_chance_level : bool, default=False
469-
Whether to plot the chance level. The chance level is the prevalence
470-
of the positive label computed from the data passed during
471-
:meth:`from_estimator` or :meth:`from_predictions` call.
478+
Whether to plot the prevalence baseline (horizontal reference line).
479+
The baseline represents the prevalence of the positive label computed
480+
from the data passed during :meth:`from_estimator` or
481+
:meth:`from_predictions` call.
482+
472483
473484
.. versionadded:: 1.3
474485
475486
chance_level_kw : dict, default=None
476-
Keyword arguments to be passed to matplotlib's `plot` for rendering
477-
the chance level line.
487+
Keyword arguments to be passed to matplotlib's `plot` for rendering
488+
the prevalence baseline line (horizontal line representing the
489+
proportion of positive samples).
490+
478491
479492
.. versionadded:: 1.3
480493

sklearn/metrics/_plot/roc_curve.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ class RocCurveDisplay(_BinaryClassifierCurveDisplayMixin):
9191
This attribute can now be a list of Artists, for when multiple curves
9292
are plotted.
9393
94-
chance_level_ : matplotlib Artist or None
95-
The chance level line. It is `None` if the chance level is not plotted.
94+
chance_level : matplotlib Artist or None
95+
The random classifier baseline line representing chance performance.
96+
It is `None` if the baseline is not plotted.
97+
98+
9699
97100
.. versionadded:: 1.3
98101

0 commit comments

Comments
 (0)