@@ -20,24 +20,23 @@ like to only compute the predictions once and one should use `from_predictions`
20
20
instead. In the following example, we plot a ROC curve for a fitted support
21
21
vector machine:
22
22
23
- .. code-block :: python
23
+ .. plot ::
24
+ :context:
25
+ :align: center
24
26
25
27
from sklearn.model_selection import train_test_split
26
28
from sklearn.svm import SVC
27
29
from sklearn.metrics import RocCurveDisplay
28
30
from sklearn.datasets import load_wine
29
31
32
+ X, y = load_wine(return_X_y=True)
33
+ y = y == 2 # make binary
30
34
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
31
35
svc = SVC(random_state=42)
32
36
svc.fit(X_train, y_train)
33
37
34
38
svc_disp = RocCurveDisplay.from_estimator(svc, X_test, y_test)
35
39
36
- .. figure :: auto_examples/miscellaneous/images/sphx_glr_plot_roc_curve_visualization_api_001.png
37
- :target: auto_examples/miscellaneous/plot_roc_curve_visualization_api.html
38
- :align: center
39
- :scale: 75%
40
-
41
40
The returned `svc_disp ` object allows us to continue using the already computed
42
41
ROC curve for SVC in future plots. In this case, the `svc_disp ` is a
43
42
:class: `~sklearn.metrics.RocCurveDisplay ` that stores the computed values as
@@ -47,23 +46,20 @@ instead of `from_estimator` Next, we train a random forest classifier and plot
47
46
the previously computed roc curve again by using the `plot ` method of the
48
47
`Display ` object.
49
48
50
- .. code-block :: python
49
+ .. plot ::
50
+ :context: close-figs
51
+ :align: center
51
52
52
53
import matplotlib.pyplot as plt
53
54
from sklearn.ensemble import RandomForestClassifier
54
55
55
- rfc = RandomForestClassifier(random_state = 42 )
56
+ rfc = RandomForestClassifier(n_estimators=10, random_state=42)
56
57
rfc.fit(X_train, y_train)
57
58
58
59
ax = plt.gca()
59
60
rfc_disp = RocCurveDisplay.from_estimator(rfc, X_test, y_test, ax=ax, alpha=0.8)
60
61
svc_disp.plot(ax=ax, alpha=0.8)
61
62
6
62E0
2
- .. figure :: auto_examples/miscellaneous/images/sphx_glr_plot_roc_curve_visualization_api_002.png
63
- :target: auto_examples/miscellaneous/plot_roc_curve_visualization_api.html
64
- :align: center
65
- :scale: 75%
66
-
67
63
Notice that we pass `alpha=0.8 ` to the plot functions to adjust the alpha
68
64
values of the curves.
69
65
0 commit comments