plot_rocplot_script with examples#
An example showing the rocplot
function
used by a scikit-learn regressor.
9 # Authors: The scikit-plots developers
10 # SPDX-License-Identifier: BSD-3-Clause
Import scikit-plot
14 import scikitplot.snsx as sp
18 ax = sp.rocplot(
19 x=[0, 1, 1, 0, 1, 0, 1, 1, 0, 1],
20 y=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 , 0.9, 1.0],
21 )

25 import numpy as np; np.random.seed(0) # reproducibility
26 import pandas as pd
27 df = pd.DataFrame({
28 "true": np.random.normal(0.5, 0.1, 100).round(),
29 "prob": np.random.normal(0.5, 0.1, 100),
30 "group": ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"]*10
31 })
PR Curve ax = sp.prplot(x=df.true, y=df.prob, hue=df.group)
37 ax = sp.rocplot(df, x="true", y="prob", label=f"classA")

41 for i in range(10):
42 np.random.seed(i) # reproducibility
43 # df = pd.DataFrame({
44 # "true": np.random.normal(0.5, 0.1, 100).round(),
45 # "prob": np.random.normal(0.5, 0.1, 100),
46 # "group": ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"]*10
47 # })
48 # ax = sp.prplot(df, x="true", y="prob", label=f"{i}")
49
50 ax = sp.rocplot(
51 x=np.random.normal(0.5, 0.1, 100).round(),
52 y=np.random.normal(0.5, 0.1, 100),
53 label=f"{i}",
54 )
55
56 # --- Collect unique handles and labels ---
57 handles, labels = ax.get_legend_handles_labels()
58 by_label = dict(zip(labels, handles)) # deduplicate
59
60 # Override legend
61 ax.legend(by_label.values(), by_label.keys(), title="Legend")

Total running time of the script: (0 minutes 0.422 seconds)
Related examples

Visualkeras: Spam Classification Conv1D Dense Example
Visualkeras: Spam Classification Conv1D Dense Example