plot_prplot_script with examples#

An example showing the prplot 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.prplot(
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 )
PR (Precision-Recall) Curve
24 import numpy as np; np.random.seed(0)  # reproducibility
25 import pandas as pd
26 df = pd.DataFrame({
27     "true": np.random.normal(0.5, 0.1, 100).round(),
28     "prob": np.random.normal(0.5, 0.1, 100),
29     "group": ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"]*10
30 })

PR Curve

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

Total running time of the script: (0 minutes 0.455 seconds)

Related examples

plot_rocplot_script with examples

plot_rocplot_script with examples

Visualkeras: Spam Classification Conv1D Dense Example

Visualkeras: Spam Classification Conv1D Dense Example

plot_residuals_distribution with examples

plot_residuals_distribution with examples

plot_residuals_distribution with examples

plot_residuals_distribution with examples

Gallery generated by Sphinx-Gallery