44import numpy as np
55import scipy as sp
66
7- from ...utils ._plotting import _BinaryClassifierCurveDisplayMixin
7+ from ...utils ._plotting import (
8+ _BinaryClassifierCurveDisplayMixin ,
9+ _deprecate_y_pred_parameter ,
10+ )
811from .._ranking import det_curve
912
1013
@@ -67,8 +70,8 @@ class DetCurveDisplay(_BinaryClassifierCurveDisplayMixin):
6770 >>> X_train, X_test, y_train, y_test = train_test_split(
6871 ... X, y, test_size=0.4, random_state=0)
6972 >>> clf = SVC(random_state=0).fit(X_train, y_train)
70- >>> y_pred = clf.decision_function(X_test)
71- >>> fpr, fnr, _ = det_curve(y_test, y_pred )
73+ >>> y_score = clf.decision_function(X_test)
74+ >>> fpr, fnr, _ = det_curve(y_test, y_score )
7275 >>> display = DetCurveDisplay(
7376 ... fpr=fpr, fnr=fnr, estimator_name="SVC"
7477 ... )
@@ -178,7 +181,7 @@ def from_estimator(
178181 <...>
179182 >>> plt.show()
180183 """
181- y_pred , pos_label , name = cls ._validate_and_get_response_values (
184+ y_score , pos_label , name = cls ._validate_and_get_response_values (
182185 estimator ,
183186 X ,
184187 y ,
@@ -189,7 +192,7 @@ def from_estimator(
189192
190193 return cls .from_predictions (
191194 y_true = y ,
192- y_pred = y_pred ,
195+ y_score = y_score ,
193196 sample_weight = sample_weight ,
194197 drop_intermediate = drop_intermediate ,
195198 name = name ,
@@ -202,13 +205,14 @@ def from_estimator(
202205 def from_predictions (
203206 cls ,
204207 y_true ,
205- y_pred ,
208+ y_score = None ,
206209 * ,
207210 sample_weight = None ,
208211 drop_intermediate = True ,
209212 pos_label = None ,
210213 name = None ,
211214 ax = None ,
215+ y_pred = "deprecated" ,
212216 ** kwargs ,
213217 ):
214218 """Plot the DET curve given the true and predicted labels.
@@ -225,11 +229,14 @@ def from_predictions(
225229 y_true : array-like of shape (n_samples,)
226230 True labels.
227231
228- y_pred : array-like of shape (n_samples,)
232+ y_score : array-like of shape (n_samples,)
229233 Target scores, can either be probability estimates of the positive
230234 class, confidence values, or non-thresholded measure of decisions
231235 (as returned by `decision_function` on some classifiers).
232236
237+ .. versionadded:: 1.8
238+ `y_pred` has been renamed to `y_score`.
239+
233240 sample_weight : array-like of shape (n_samples,), default=None
234241 Sample weights.
235242
@@ -253,6 +260,15 @@ def from_predictions(
253260 Axes object to plot on. If `None`, a new figure and axes is
254261 created.
255262
263+ y_pred : array-like of shape (n_samples,)
264+ Target scores, can either be probability estimates of the positive
265+ class, confidence values, or non-thresholded measure of decisions
266+ (as returned by “decision_function” on some classifiers).
267+
268+ .. deprecated:: 1.8
269+ `y_pred` is deprecated and will be removed in 1.10. Use
270+ `y_score` instead.
271+
256272 **kwargs : dict
257273 Additional keywords arguments passed to matplotlib `plot` function.
258274
@@ -278,19 +294,20 @@ def from_predictions(
278294 >>> X_train, X_test, y_train, y_test = train_test_split(
279295 ... X, y, test_size=0.4, random_state=0)
280296 >>> clf = SVC(random_state=0).fit(X_train, y_train)
281- >>> y_pred = clf.decision_function(X_test)
297+ >>> y_score = clf.decision_function(X_test)
282298 >>> DetCurveDisplay.from_predictions(
283- ... y_test, y_pred )
299+ ... y_test, y_score )
284300 <...>
285301 >>> plt.show()
286302 """
303+ y_score = _deprecate_y_pred_parameter (y_score , y_pred , "1.8" )
287304 pos_label_validated , name = cls ._validate_from_predictions_params (
288- y_true , y_pred , sample_weight = sample_weight , pos_label = pos_label , name = name
305+ y_true , y_score , sample_weight = sample_weight , pos_label = pos_label , name = name
289306 )
290307
291308 fpr , fnr , _ = det_curve (
292309 y_true ,
293- y_pred ,
310+ y_score ,
294311 pos_label = pos_label ,
295312 sample_weight = sample_weight ,
296313 drop_intermediate = drop_intermediate ,
0 commit comments